希望在linq中帮助嵌套组,我试图降低三级。
基本上,路径会从业务下降到 BusUnit 到 Level1
因此,在Business下有各种BusUnit,在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以便返回值?
答案 0 :(得分:1)
您可以指定要包含在查询结果中的相关对象。准确的代码片段取决于您使用的LINQ提供程序。对于Entity Framework,它将是:
... from r in DataItems.Include(di => di.Business.Businessunit.Level1) ...