How to use IN statement in linq

I request a view and filters the results with a column called status. I would like to request it so that I can search for rows with different status using the IN statement, as it would in SQL.

So:

SELECT * FROM VIEW WHERE Status in ('....', '.....')

How can i achieve this?

+8
c # linq linq-to-objects
Jun 11 '10 at 15:47
source share
1 answer

If the query expression uses the Contains method of the IEnumerable , then the parser will turn it into an IN expression using the values ​​in IEnumerable .

 List<string> foo = new List<string>() { "a", "b", "c" }; var query = dataContext.View.Where(v => foo.Contains(v.Status)); 
+18
Jun 11 '10 at
source share



All Articles