如何在Linq中使用IN运算符?

时间:2010-04-26 15:30:27

标签: linq-to-sql asp.net-mvc-2

查询:

Select * from pu_Products 
    where Part_Number in ('031832','027861', '028020', '033378') 
    and User_Id = 50 and Is_Deleted = 0

上面提到的查询是在SQL中我需要将查询转换为Linq。在Linq中有没有使用“IN”运算符的选项?你能将上面提到的查询转换成Linq吗?

1 个答案:

答案 0 :(得分:4)

dbContext.Products
    .Where(p => (new string[] {"031832","027861","028020","033378"})
        .Contains(p.Part_Number) && p.Is_Deleted == false);