Muh*_*tar 15 c# sql entity-framework
可能重复:
Linq to Entities - Sql"IN"子句
如何在Entity framework 4.0中实现SQL"in"
我怎样才能添加WHERE IN语句...
SELECT * FROM myTable WHERE ID IN (1,2,3,4,5)
Run Code Online (Sandbox Code Playgroud)
在实体框架中
Jon*_*eet 65
用途Contains
:
int[] ids = { 1, 2, 3, 4, 5};
var query = db.myTable.Where(item => ids.Contains(item.ID));
Run Code Online (Sandbox Code Playgroud)
或者在查询语法中:
int[] ids = { 1, 2, 3, 4, 5};
var query = from item in db.myTable
where ids.Contains(item.ID)
select item;
Run Code Online (Sandbox Code Playgroud)