开发者

LINQ to SQL filter by List<int>

开发者 https://www.devze.com 2023-01-13 08:12 出处:网络
Ho开发者_如何学Pythonw can I retreive rows from table only when UserId is in my Users list ? Code below doesnt work :/

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...)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号