c# - linq - order by who has been selected -
i wondering how orderby has been selected in list in linq.
for example, have 4 names in list
bob sue ryan sarahjust numbers beside them associated id.
so user selects "sue , sarah" - want sue , sarah on top of list
2 - sue 4 - sarah 1 - bob 3 - ryan
the linq have is
list<entity> = list.orderby(x => x.id == idsselected).groupby() // not grouping by... any ideas?
thanks in advance
you can utilize orderby bool have utilize orderbydescending if trues should on top of list( remember treating true 1 , false 0):
list<entity> = list .orderbydescending(x => idsselected.contains(x.id)) .thenby(x => x.name) // if desired .tolist(); c# linq
No comments:
Post a Comment