admin

LINQ to Entities-查询中的IN子句

sql

我如何添加WHERE IN语句,如…

SELECT * FROM myTable WHERE ID IN (1,2,3,4,5)

在实体框架中


阅读 233

收藏
2021-05-10

共1个答案

admin

用途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;
2021-05-10