Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass an array of OrderBy expression to a method?
    primarykey
    data
    text
    <p>I'm trying to enhance my repository so it is the one responsible for ordering. I've applied the answer from <a href="https://stackoverflow.com/questions/3084671/linq-multiple-order-by">this question</a> and as far as the repository is concerned, I'm pretty sure it done.</p> <p>The problem I'm running into is that I'm not sure how to now pass an array to the methods in the repository. The compiler keeps yelling at me about delegates. In the linked question above, the author is essentially doing what I want so it must be possible.</p> <p>Here's my repository code:</p> <pre><code>public virtual IList&lt;TEntity&gt; SelectOrderedList( Expression&lt;Func&lt;TEntity, bool&gt;&gt;[] Orderers, bool Ascending = true) { IOrderedQueryable&lt;TEntity&gt; TemporaryQueryable = null; foreach (Expression&lt;Func&lt;TEntity, bool&gt;&gt; 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(); } </code></pre> <p>On a side note, I'm not 100% sure that I'm supposed to use <code>Expression&lt;Func&lt;TEntity, bool&gt;&gt;</code>. For some reason I have a feeling that it's supposed to be <code>Expression&lt;Func&lt;TEntity, int&gt;&gt;</code>, but I'm not too sure.</p> <p>Anyway, I would really appreciate it if someone can show me how to actually call that. Bonus points and love if you can make it work like a <code>params</code> argument.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload