如何仅当 UserId 在我的用户列表中时才从表中检索行?
下面的代码不起作用:/
List<int> selectedSourceUsers = ...
MyModelDataContext context = ...
e.Result = from u in context.Users
from id in selectedSourceUsers
where u.UserId == id
select u;
感谢帮助
最佳答案
试试这个:
int[] selectedUsersArray = selectedSourceUsers.ToArray();
e.Result = from u in context.Users
where selectedUsersArray.Contains(u.UserId)
select u;
(老实说,我原以为它也可以与 List<int>
一起使用,但改用数组可能会解决问题...)
关于c# - LINQ to SQL 按 List<int> 过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3555511/