c# - Using Linq Grouping how to I order by specific Group then remaining Groups descending -


this code working example of content of select case statement. in response link button click who's id passed in via session variable. link buttons represent high(3) medium(2) , low(1) risk categories.

the logic here is; if select medium(2) it's related rows (riskcategory =2) displayed first remaining rows ( risk category ) listed descending 3 2 0)

as said ugly implementation of linq concat function accomplish goal produce correct results, showcases need spend more weekends reviewing , creating better intricate samples simple 101 link samples tutorial project provides.

there must more elegant way group , order while allowing groups ordered representing selected group first, remaining groups descending. again select group 1 lowriskcategory, i'll have display lowriskcategory first (1) 3, 2, & 0 respectively in sorted results set.

var midquery = enumerableversiontable.where(x => x["riskcategory"].equals(intriskcategoryenum));                                     midquery.orderbydescending(v => v["dateofservice"]); midquery.orderby(v => v["reviewed"]);  var midqueryzero = enumerableversiontable.where(x => x["riskcategory"].equals(0)); midqueryzero.orderbydescending(v => v["dateofservice"]); midqueryzero.orderby(v => v["reviewed"]);  var midqueryone = enumerableversiontable.where(x => x["riskcategory"].equals(1)); midqueryone.orderbydescending(v => v["dateofservice"]); midqueryone.orderby(v => v["reviewed"]);  var midquerythree = enumerableversiontable.where(x => x["riskcategory"].equals(3)); midquerythree.orderbydescending(v => v["dateofservice"]); midquerythree.orderby(v => v["reviewed"]);  var querysummation = midquery.concat(midquerythree); querysummation = querysummation.concat(midqueryone); querysummation = querysummation.concat(midqueryzero); dtqueryresults = querysummation.copytodatatable() 

just sight of hardcoded numeral values after translated enum value case 2: makes me wana hurl. theres gotta more elegant way groups. order specific group. , of course apply other odd sorting, see date of service , reviewed.

lastly if going again vote down @ least explain why please thank

var dtqueryresults = yourdata             .orderbydescending(v => v["riskcategory"] == intriskcategoryenum)//true ==2 goes first, false goes             .thenby(v => v["riskcategory"]) //the rest sorted             .thenby(v => v["reviewed"]) //inside groups, rest of sorts used             .thenbydescending(v => v["dateofservice"]); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -