Geeks With Blogs
Guilherme Cardoso, Blog EN .NET geek

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

                                 into g
                                 select new
                                                Month = g.Select(n => n.DateOfPayment.Value.Month).First(),
                                                TotalAmount = g.Sum(n => (Decimal) n.TotalAmount),
                                                CountOrders = g.Count()


Posted on Friday, July 16, 2010 2:57 AM | Back to top

Comments on this post: LINQ - Group By Month, Sum some value and count

# re: LINQ - Group By Month, Sum some value and count
Requesting Gravatar...
Thanks very much, this is what I was looking for.
Left by Brent on Nov 30, 2011 3:09 AM

Your comment:
 (will show your gravatar)

Copyright © Guilherme Cardoso | Powered by: | Join free