score:2

Accepted answer

For the count you just need this query:

int total = pieces
    .Where(x => x.Count > 0)
    .GroupBy(x => new { x.Count, x.Date, x.Description })
    .Sum(g => g.Key.Count);

So you can access all key properties of the grouping.

This returns 85 for your initial sample and 108 if you add the new piece.


Related Articles