gpt4 book ai didi

c# - IQueryable 按 ID 列表过滤

转载 作者:可可西里 更新时间:2023-11-01 08:37:15 26 4
gpt4 key购买 nike

假设我们有一个 IQueryable<T> . Where子句可以按单个 ID 值过滤,但我如何返回 IQueryable基于 ID 列表?

[TestMethod]
public void TestIQueryableWithList()
{
int ID1 = 1;
List<int> IDs = new List<int> { 1, 3, 4, 8 };

using (var db = new SellooEntities())
{
// works fine as single value
var iq = db.tblSearches.Where(x => x.seaUserId == ID1);

// how can i do it to check for all the IDs ??
foreach(int ID in IDs)
{
// this obviously wont work
var iq = db.tblSearches.Where(x => x.seaUserId == ID);
}
}
}

最佳答案

tblSearches 获取数据,其中 seaUserIdIDs 列表中:

[TestMethod]
public void TestIQueryableWithList()
{
int ID1 = 1;
List<int> IDs = new List<int> { 1, 3, 4, 8 };

using (var db = new SellooEntities())
{
var iq = db.tblSearches.Where(x => IDs.Contains(x.seaUserId);
}
}

关于c# - IQueryable<T> 按 ID 列表过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13669913/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com