Reputation: 9053
Was hoping for some help with Nested group by in linq where I am trying to go down three levels.
Basically the path would go down Business to BusUnit to Level1
So under Business there are various BusUnits and under BusUnits there are various level1 values
I want to return this as a Json object.
As I have it at the moment I got down to BusUnits
as follow
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 })
});
How could I get to Level1 so as to return the values as well?
Upvotes: 0
Views: 45
Reputation: 2066
You can specify related objects to include in the query results. Exact snippet depends from LINQ provider you are using. For Entity Framework it will be:
... from r in DataItems.Include(di => di.Business.Businessunit.Level1) ...
Upvotes: 1