I'm very new to LINQ, I've searched the boards but none of the other q/a's give a complete sample. I need to query with LINQ a strongly typed IList<>
object and I must:
- Sum by a property
- Group by a property
- Order by the same property I did Sum on
- Limit the result to top 2
For example if my data is like this:
Id | Customer | CartTotal
-------------------------------
1 | a | 100
2 | a | 50
3 | b | 110
4 | b | 128
5 | c | 75
6 | c | 30
My result needs to be like this where I've limited it top 2, grouped by customer, and done a sum on CartTotal:
Customer | CartTotal
----------------------
b | 238
a | 150
What's the best way of accomplishing this?