tags:

views:

31

answers:

2

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', 'Admin', 'Docs'). How can I accomplish this? Thanks

+2  A: 

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;
anishmarokey
+1  A: 

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.)

Jon Skeet