views:

59

answers:

1

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 subsonic3 with a SimpleRepository if that makes a difference (or allows me to use something else to make this easier).

+2  A: 
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;
zerkms
SoftwareGeek
@SoftwareGeek: i did not test them actually :-S but if i would do that - then i will just create list of integers and make something close to the tested one. don't you agree that doesn't matter whether we use LINQ with objects or integers?
zerkms
Thanks zerkms, I learnt a bit from googling the terminology in the second example.
George R
SoftwareGeek
@George R: http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx - this can be useful too
zerkms