LINQ to SQL filter by List<int>
Ho开发者_如何学Pythonw can I retreive rows from table only when UserId is in my Users list ?
Code below doesnt work :/
List<int> selectedSourceUsers = ...
MyModelDataContext context = ...
e.Result = from u in context.Users
from id in selectedSourceUsers
where u.UserId == id
select u;
Thanks for help
Try this:
int[] selectedUsersArray = selectedSourceUsers.ToArray();
e.Result = from u in context.Users
where selectedUsersArray.Contains(u.UserId)
select u;
(To be honest I'd have expected it to work with a List<int>
as well, but using an array instead may fix it...)
精彩评论