OK, another LINQ question. How do I do an \"IN\" condition using LINQ. I have an IEnumerable list of myObject and want to do something like myObject.Description in(\'Help\',
Use Contains
on a collection:
string[] descriptions = { "Help", "Admin", "Docs" };
var query = from foo in list
where descriptions.Contains(foo.Description)
select ...;
(For larger collections, a HashSet<T>
might be better.)
IN in sql is equivalent is Contains
in LINQ
string[] countries = new string[] { "UK", "USA", "Australia" };
var customers =
from c in context.Customers
where countries.Contains(c.Country)
select c;