views:

122

answers:

1

Query:

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

The above mentioned query is in SQL and i need the query might be converted into Linq. Is there any option using the "IN" operator in Linq?. can you convert above mentioned query into Linq?

+3  A: 
dbContext.Products
    .Where(p => (new string[] {"031832","027861","028020","033378"})
        .Contains(p.Part_Number) && p.Is_Deleted == false);
Justin Niessner
While correct, this isn't very efficient. It's better (and more readable IMO) to define the string array outside of the where. Still, my +1.
Steven