c# - Multiple linq query of order by to single one -
this question has reply here:
evaluate column name in linq clause 2 answersi have multiple line status order below
if (enum1) { var = itemlist.orderby(r => r.column1) } else if (emum2) { var = itemlist.orderby(r => r.column2) }
and on.. way such thing dynamically.
what can improve manage column selection sorting, e.g. using collection holds func<> keyselector.
e.g. if have class name 'somedto' 4 properties, prop1,2,3 , 4. , 4 corresponding enum members.
var searchbymapping = new dictionary<searchbyenum,func<somedto, object>>(); searchbymapping.add(searchbyenum.prop1, x => x.prop1); searchbymapping.add(searchbyenum.prop2, x => x.prop2); searchbymapping.add(searchbyenum.prop3, x => x.prop3); coll = coll.orderby(searchbymapping[searchbyenumparam]).tolist();
this not dynamic approach typesafe one.
c# linq delegates
No comments:
Post a Comment