I have an entity i would say it as "Items", Structure of this entity like below,
string itemName
int groupId
decimal itemPrice
int itemQty
first i wanted to group it by groupId
and return it as a list of list of items (List<List<Items>>
)
I followed this instruction and successfully did it. Using Linq to group a list of objects into a new grouped list of list of objects
Here is my code to get that List<List<Item>>
var groupedItem = rawItemData
.GroupBy(u => u.groupId)
.Select(grp => grp.ToList())
.ToList();
But now i want to order each group(list) by getting summation of itemPrice on it.
Example for my expectation:
- 1st element of my result has 5 Items, Summation of item price in this group is 350
- 2nd element of my result has 10 Items, Summation of item price in this group is 500
- 3rd element of my result has 2 Items, Summation of item price in this group is 150
- 4th element of my result has 6 Items, Summation of item price in this group is 555
I want to group my main result by this summation of item price,
Expected order is like below, 4th element, 2nd element, 1st element, 3rd element.
Something very hard to explain, Please let me know if need more clarification on this question.
Thank you very much!