Geeks With Blogs
Guilherme Cardoso, Blog EN .NET geek July 2010 Entries
LINQ - Group By Month, Sum some value and count
The following example group an list by year, month. It counts how much records the groups has and sums some values from the group (in this case is money). var orders = from ord in Lista group enc by new { ord.DateOfPayment.Value.Year, ord.DateOfPayment.Value.Month } into g select new { Month = g.Select(n => n.DateOfPayment.Value.Month... TotalAmount = g.Sum(n => (Decimal) n.TotalAmount), CountOrders = g.Count() }; ......

Posted On Friday, July 16, 2010 2:57 AM

Copyright © Guilherme Cardoso | Powered by: GeeksWithBlogs.net