Click here to Skip to main content
15,924,195 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai to all ,
i have List<expenserecord> , that list contains Id, Name, Amount.
Example: Id | Name | Amount
--------------------
1 | a | 50
2 | b | 10
3 | c | 40
4 | d | 6
5 | a | 5
6 | c | 80

from that i have to select the Name and Amount like the below

Name | Amount
----------------------
a | 55
b | 10
c | 120
d | 6
(above i made the Some of Amount which contains the same name)

How can i write querry to retrive data like that

Please help me...
Posted

1 solution

It's just a simple group by query in LINQ.

C#
var result =
        from p in table
        group p by p.Name into g
        select new { Name = g.Key, TotalAmount = g.Sum(p => p.Amount) };
 
Share this answer
 
Comments
TweakBird 8-Jan-11 0:51am    
Good call Hiren
satyagrahi_2010 26-Feb-11 5:07am    
Thanks helped me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900