首页 > 代码库 > Linq 构造复杂Json 多表group by

Linq 构造复杂Json 多表group by

一个主表A(a1,a2),子表B(a1,b1,b2) ,想得到的结果是 [{a1,a2,Info [{b1,b2},{b1,b2},...}]]

var list=

from a in A

join b in B on a.a1=b.a1

group b by a into g

select new {

g.key.a1,

g.key.a2,

Info=g.select (c=>new {c.b1,c.b2}).ToList()

}.tolist()

Linq 构造复杂Json 多表group by