开发者

linq2sql and multiple joins

is it possible to do multip开发者_开发百科le 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


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;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜