c# - How to pass an array of OrderBy expression to a method? -
i'm trying enhance repository 1 responsible ordering. i've applied answer this question , far repository concerned, i'm pretty sure done.
the problem i'm running i'm not sure how pass array methods in repository. compiler keeps yelling @ me delegates. in linked question above, author doing want must possible.
here's repository code:
public virtual ilist<tentity> selectorderedlist( expression<func<tentity, bool>>[] orderers, bool ascending = true) { iorderedqueryable<tentity> temporaryqueryable = null; foreach (expression<func<tentity, bool>> orderer in orderers) { if (temporaryqueryable == null) { temporaryqueryable = (ascending ? this.objectset.orderby(orderer) : this.objectset.orderbydescending(orderer)); } else { temporaryqueryable = (ascending ? temporaryqueryable.thenby(orderer) : temporaryqueryable.thenbydescending(orderer)); }; }; return temporaryqueryable.tolist(); }
on side note, i'm not 100% sure i'm supposed use expression<func<tentity, bool>>
. reason have feeling it's supposed expression<func<tentity, int>>
, i'm not sure.
anyway, appreciate if can show me how call that. bonus points , love if can make work params
argument.
public virtual ilist<tentity> selectorderedlist( params expression<func<tentity, icomparable>>[] orderers) { iorderedqueryable<tentity> temporaryqueryable = null; foreach (expression<func<tentity, icomparable>> orderer in orderers) { if (temporaryqueryable == null) { temporaryqueryable = this.objectset.orderby(orderer); } else { temporaryqueryable = temporaryqueryable.thenby(orderer); }; }; return temporaryqueryable.tolist(); }
then use selectorderedlist(o1 => (o1.something), o2 => (o2.somethingelse))
...
also, write descending :)
if want one, each orderer can ascending or descending, replace signature tuple>,sortdirection> cannot use implicitly typed lambdas implicitly typed tuples (and cannot use them implicit expressions either) then, you'd have quite ugly code when using it...
Comments
Post a Comment