c# - Group by year descending, order by month and total on another column Linq query -
have linq query working, can't figure out how descending order. here have far:
list.groupby(grp => grp.year) .selectmany(g => g.orderby(grp => grp.month)) .tolist(); which produces following results:
month in correct order except year needs in descending order. this:
this might ask need run total of days per grouped year. appreciate help!
the data looks this:
the answer worked me this:
list.orderbydescending(grp => grp.year).thenby(grp => grp.month).tolist()
two comments:
you "grouping" data, turning around , un-grouping via
selectmany, throws away grouping; puts data groups, not in configurable order. select of data in 1 go, ordering year descending, month:list.orderbydescending(l => l.year) .thenby(l => l.month));adding "group footers" show subtotals job of presentation layer, not data layer. could create hybrid list inserts total "row" data, more straightforward add group footer configuring whatever control presenting data rather inserting subtotals raw data.



Comments
Post a Comment