0

我有三张桌子ABCC有很多B,有很多A

我想在树中显示所有这些数据,所以我绑定db.A到具有三层层次结构的嵌套控件。唯一的问题是我得到了太多行,因为它没有在 and 之间进行内部B连接C

那么我怎么能在 linq 中做这样的事情:

SELECT A.name, B.name
FROM A
INNER JOIN B ON A.id = B.AID 
INNER JOIN C ON B.id = C.BID
GROUP BY A.Name, B.Name
ORDER BY A.Name

我尝试了以下方法无济于事:

from a in A
join b in B on a.id equals b.AID
join c in C on b.id equals c.BID
select c

非常感谢

4

1 回答 1

0

试试这个 :

from a in A 
join b in B on a.id equals b.AID 
join c in C on b.id equals c.BID 
group new {a,b} by new {a.name,b.name} into g
select g

上面的连接与您在 sql 查询中所做的相同,但您想要的是:

from a in A 
join b in B on a.id equals b.AID 
join c in C on b.id equals c.BID 
group c by c.name into g
select g
于 2012-06-12T12:16:24.040 回答