希望在 linq 中对 Nested group by 有所帮助,我正在尝试降低三个级别。
基本上这条路会从Business到BusUnit到Level1
因此,在 Business 下有各种 BusUnits,在 BusUnits 下有各种 level1 值
我想将此作为 Json 对象返回。
正如我现在所拥有的那样,我来到了 BusUnits
如下
var queryNestedData = (from r in DataItems
group r by r.Business into businesses
from businessUnits in
(from r in businesses
group r by r.Businessunit)
group businessUnits by businesses.Key).Select(tg =>
new
{
Business = tg.Key,
BusinessUnits = tg.Select(tv => new { BusinessUnit = tv.Key })
});
我怎样才能到达 Level1 以便也返回值?