LinQ to objects GroupBy() by object and Sum() by amount

Posted by Daniil Harik on Stack Overflow See other posts from Stack Overflow or by Daniil Harik
Published on 2010-03-31T07:18:39Z Indexed on 2010/03/31 7:23 UTC
Read the original article Hit count: 517

Filed under:
|
|
|

Hello,

I have pretty simple case which I started solving using foreach(), but then I thought I could do It using Linq

Basically I have IList that contains PaymentTransaction objects and there are 2 properties Dealer and Amount

I want to GroupBy() by Dealer and Sum() bv amount.

I tried to accomplish this using following code, but unfortunately it does not work

var test = paymentTransactionDao.GetAll().GroupBy(x => x.Dealer).Sum(x => x.Amount);

Want exactly I'm doing wrong here?

I'm sorry if this question is too simple.

Thank You

© Stack Overflow or respective owner

Related posts about linq-to-objects

Related posts about LINQ