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:

partially working output

month in correct order except year needs in descending order. this:

enter image description here

this might ask need run total of days per grouped year. appreciate help!

the data looks this:

enter image description here

the answer worked me this:

list.orderbydescending(grp => grp.year).thenby(grp => grp.month).tolist() 

two comments:

  1. 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)); 
  2. 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

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -