score:1

Accepted answer
var custList = new HashSet<string>() { "a", "b", "c"...};

from record in table.ToEnumerable()
where custList.Contains(record.Field<string>("customerID"))

score:2

In LINQ you use the Contains() method to perform these kind of queries.

I don't know LINQ to DataSets, but in LINQ to SQL you can do the following:

var statuses = new int[] {1, 2, 3};

var query = from p in dataContext.Products
            where statuses.Contains(p.Id)
            select p;

This should generate SQL similar to:

select * from Product p
where p.Id in (1, 2, 3)

(Note how it feels back-to-front in the LINQ code to the generated SQL - that's why if you know SQL well it's not very intuitive, but it makes very elegant use of existing .NET language features)

This also typically works for string and collections of some other basic types that L2S knows about because they're in the framework.

score:0

var custList = new HashSet<int> { 10, 15, 17 };
CustomerSet.Where(c => custList.Contains(c.CustomerID));

Related Articles