开发者

Nested linq - where x == enumerable

开发者 https://www.devze.com 2023-01-10 05:49 出处:网络
I\'m new to Linq and SQL terminology - can someone tell me why this isn\'t working (syntax is not right - I can\'t compare u.UserID int with an Enumerable)

I'm new to Linq and SQL terminology - can someone tell me why this isn't working (syntax is not right - I can't compare u.UserID int with an Enumerable)

var projectUsers = from u in SimpleRepository.All<User>()
                   where u.UserID == (from i in SimpleRepository.All<ProjectUser>()
                                      where i.ProjectID == p.ProjectID
                                      select i.UserID)
                   select u;

In "english", that would we "select every user where their id matches any of (userID from ProjectUser collection where projectID == x) and give me a collection of users".

I'm also using su开发者_如何转开发bsonic3 with a SimpleRepository if that makes a difference (or allows me to use something else to make this easier).


var projectUsers = from u in SimpleRepository.All<User>()
               where (from i in SimpleRepository.All<ProjectUser>()
                                  where i.ProjectID == p.ProjectID
                                  select i.UserID).Contains(u.UserID)
               select u;

or

var projectUsers = from u in SimpleRepository.All<User>()
               join u2 in SimpleRepository.All<ProjectUser>() on u.UserID equals u2.UserId
               where u2.ProjectID == p.ProjectID
               select u;
0

精彩评论

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

关注公众号