8
假設我們有一個IQueryable<T>
。 Where
子句可以通過單個ID值進行過濾,但是如何根據ID列表返回IQueryable
?從tblSearches
IQueryable <T>按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);
}
}
}