LINQ

GroupBy child object properties and return Count and Sum

var results = invoices.GroupBy(x => new
{
    x.Account.Id,
    x.Account.AccountName
})
.Select(x => new
{
    AccountId = x.Key.Id,
    AccountName = x.Key.AccountName,
    Count = x.Count(),
    TotalCost = x.Sum(inv => inv.Total)
});

Sponsored by