开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜