可能重复:
Linq to Entities - Sql “IN” clause
How to implement SQL “in” in Entity framework 4.0
如何添加WHERE IN语句,如...
SELECT * FROM myTable WHERE ID IN (1,2,3,4,5)
实体框架中的
答案 0 :(得分:64)
使用Contains
:
int[] ids = { 1, 2, 3, 4, 5};
var query = db.myTable.Where(item => ids.Contains(item.ID));
或查询语法:
int[] ids = { 1, 2, 3, 4, 5};
var query = from item in db.myTable
where ids.Contains(item.ID)
select item;
答案 1 :(得分:2)
我认为答案就在这些方面......
Array a = {1,2,3,4,5}
...WHERE a.Contains(ID)