Apr 19, 2016 09:03 AM|Cole Wu|LINK
But then I can't find a way of populating the sub object of Products using this method.
Per your code snippet, I create a similar demo for your reference.
var query = (from p in _db.Products
join pg in _db.ProductGroups on p.ProductGroupId equals pg.ProductGroupId
where p.Active == 1
orderby pg.ProductGroupName ascending, p.ProductName ascending
group pg by pg.ProductGroupName into gg
ProductGroupName = gg.Key,
Products = gg.Select(c=>c.Products).FirstOrDefault()
In addition, you could use any method to achieve it. like this:
var result = _db.ProductGroups.Include("Products").Where(pg => pg.Products.Any(p => p.Active == 1)).ToList();