我有一个从数据库中获取记录的查询, 我需要在参数中传递 ids 来调用这个函数, 像 Myfunction(1, 2, 3)
我想得到与这个id匹配的结果,
喜欢
public List<Items> GetItems(int[] ids)
{
var a = from Items in db.item
where items.id == ids[]
select new Items
{
}
return a.ToList();
}
在 where 子句上存在混淆(如何获取有关提供的记录)
我试过循环 id 但没有成功
提前致谢
最佳答案
您可以使用Contains, 方法来检查。类似于 Select * from table where IDs in (1,2,3,...)
尝试以下操作。
var a = from item in db.Items
where ids.Contains(item.id)
select new Item {.....}
ids
是您的数组。
关于c# - 如何使用多参数linq从数据库中获取记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13025687/