Possible Duplicates:
Linq to Entities - Sql “IN” clause
How to implement SQL “in” in Entity framework 4.0
how can I add WHERE IN statement like...
SELECT * FROM myTable WHERE ID IN (1,2,3,4,5)
in entity framework
We can remove all duplicates like this by using GroupBy and Select methods provided by LINQ . First, we group our list so that we will create groups for each name in the List. Then we use Select to only select the first objects in each group. This will result in the removal of the duplicates.
A single query expression may have multiple where clauses.
Introduction to LINQ Include. LINQ include helps out to include the related entities which loaded from the database. It allows retrieving the similar entities to be read from database in a same query. LINQ Include() which point towards similar entities must read from the database to get in a single query.
The C# code editor supports LINQ extensively with IntelliSense and formatting capabilities.
Use Contains
:
int[] ids = { 1, 2, 3, 4, 5};
var query = db.myTable.Where(item => ids.Contains(item.ID));
or in query syntax:
int[] ids = { 1, 2, 3, 4, 5};
var query = from item in db.myTable
where ids.Contains(item.ID)
select item;
I think answer lies somewhere along these lines...
Array a = {1,2,3,4,5}
...WHERE a.Contains(ID)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With