What is LINQ equivalent of SQL’s “IN” keyword

后端 未结 4 1635
暗喜
暗喜 2021-01-05 00:22

How can I write below sql query in linq

select * from Product where ProductTypePartyID IN
(
    select Id from ProductTypeParty where PartyId = 34
)
<         


        
4条回答
  •  礼貌的吻别
    2021-01-05 01:14

    You use the Contains in a Where clause.

    Something along these lines (untested):

    var results = Product.Where(product => ProductTypeParty
                                                .Where(ptp => ptp.PartyId == 34)
                                                .Select(ptp => ptp.Id)
                                                .Contains(product.Id)
                               );
    

提交回复
热议问题