I have a LINQ to SQL query returning rows from a table into an IQueryable object.
IQueryable<MyClass> items = from table in DBContext.MyTable select new MyClass { ID = table.ID, Col1 = table.Col1, Col2 = table.Col2 }
Then I want to execute the SQL query "WHERE ... IN ...." on the results. This works great using the following. (return results with ID ID1 ID2 or ID3)
sQuery = "ID1,ID2,ID3"; string[] aSearch = sQuery.Split(','); items = items.Where(i => aSearch.Contains(i.ID));
What I would like to do does the same operation, but you do not need to specify the i.ID part. Therefore, if I have a field name string, I want to apply the WHERE IN clause, how can I use this in the .Contains () method?
matt source share