具有组计数的LINQ查询

时间:2015-09-16 02:40:59

标签: sql .net linq

我试图制作一个linq句子,但我被卡住了。 我想模仿的SQL是:

navbar

我无法弄明白......

2 个答案:

答案 0 :(得分:0)

试试这个..

from t in table
join t1 in table1
    on t1.id equals t.id
join t2 in table2
on t2.id equals t.id
group t by t.id into g
select new
{
    rCount1 = g.Count(k => k.t1.id),
    rCount2 = g.Count(k => k.t2.id),
    name = g.key.name
}

答案 1 :(得分:0)

试试这种方式

from a in contex.name
from b in contex.table1.where(x=>x.id==a.id)
from c in contex.table2.where(x=>x.id==a.id)
group a by a.Id into g
select new{rCount1 = g.Count(x => x.t1.id), rCount2 = g.Count(x => x.t2.id),
name = g.key.name }