Home Linq 'Group by' example
Post
Cancel

Linq 'Group by' example

Example

1
2
3
4
5
6
7
8
9
var query = (from t in Transactions
             group t by new {t.MaterialID, t.ProductID}
             into grp
                    select new
                    {
                        grp.Key.MaterialID,
                        grp.Key.ProductID,
                        Quantity = grp.Sum(t => t.Quantity)
                    }).ToList();

From http://stackoverflow.com/questions/847066/group-by-multiple-columns

This post is licensed under CC BY 4.0 by the author.