tags:

views:

31

answers:

1

is it possible to do multiple joins:

from g in dataContext.Groups
join ug in dataContext.UsersGroups on g.Id equals ug.GroupId
join u in dataContext.Users on u.
where ug.UserId == user.Id
select GroupRepository.ToEntity(g);

in the sample above all is fine until i press "." in the end of the 3rd line. there i expect to get intellisense and write u.Id == ug.UserId but it doesn't appear. and of course this code doesn't compile after.

what did i wrong?

ANSWER: the order of aliases is important. so i've used ug.UserId equals u.Id

A: 

The following code works for me in LINQ to SQL (Northwind database)

 var dataContext = new NorthwindDataContext();
 var x = from c in dataContext.Customers
       join o in dataContext.Orders on c.CustomerID equals o.CustomerID
       join od in dataContext.Order_Details on o.OrderID equals od.OrderID
       select c;
Raj Kaimal
i mark this answer just because i have to choose something, not because it actually answers to my question ;-)
zerkms
Try breaking apart your code one step at a time. ie.. first remove the second join, then make the select statement and make it simply select g. See if it compies and runs. Now add the second join back but leave select alone. compile. and so on...
Raj Kaimal
@Raj: i already answered my question with myself before add my prev comment ;-) btw, i do know how to debug and how to write code iteratively. and as i said (to prevent such kind of advices) before i added dot in the end all IS FINE AND COMPILES ;-)
zerkms
Sorry did not notice you updated your question.
Raj Kaimal