Grouping and Summing with Lambda Expressions

var query = invoiceList 
            .GroupBy(g => new { g.InvoiceDate, 
                                g.InvoiceType }) 
            .Select(group => new { 
                       InvoiceDate = group.Key.InvoiceDate, 
                       InvoiceType = group.Key.InvoiceType, 
                       TotalAmount = group.Sum(a=>a.InvoiceAmount), 
                       TotalCount = group.Sum(c=>c.NumberOfItems)});

http://msmvps.com/blogs/deborahk/archive/2010/05/03/grouping-and-summing-with-lambda-expressions.aspx

 

Loading