开发者

linq2sql and multiple joins

开发者 https://www.devze.com 2022-12-28 15:47 出处:网络
is it possible to do multip开发者_开发百科le joins: from g in dataContext.Groups join ug in dataContext.UsersGroups on g.Id equals ug.GroupId

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

精彩评论

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

关注公众号