title: OrderBy based on list of fields and Asc / Desc rules
body: <p>I have the following <code>List</code> with <code>OrderBy</code> parameters:</p>
  
  <pre><code>List&lt;String&gt; fields = new List&lt;String&gt; { "+created", "-approved", "+author" }
  </code></pre>
  
  <p>This would result in the following Linq query:</p>
  
  <pre><code>IQueryable&lt;Post&gt; posts = _context.posts.AsQueryable();
  
  posts = posts
     .OrderBy(x =&gt; x.Created)
     .ThenByDescending(x =&gt; x.Approved);
     .ThenBy(x =&gt; x.Author.Name);
  </code></pre>
  
  <p>So basically the rules are:</p>
  
  <ol>
  <li>Use the first item in the <code>OrderBy</code> and the others in <code>ThenBy</code>.</li>
  <li>Use descending when the field starts with <code>-</code> and ascending when with <code>+</code>.</li>
  </ol>
  
  <p>My idea would be to have something like:</p>
  
  <pre><code>OrderExpression expression = posts
    .Add(x =&gt; x.Created, "created")
    .Add(x =&gt; x.Approved, "approved")
    .Add(x =&gt; x.Author.Name, "author");
  </code></pre>
  
  <p>So the expression associates the post properties / child properties to each key in fields. Then it would be applied as follows:</p>
  
  <pre><code>posts = posts.OrderBy(expression, fields);
  </code></pre>
  
  <p>So the <code>OrderBy</code> extension would go through each item in the OrderExpression and apply the rules (1) and (2) to build the query:</p>
  
  <pre><code>posts = posts
     .OrderBy(x =&gt; x.Created)
     .ThenByDescending(x =&gt; x.Approved);
     .ThenBy(x =&gt; x.Author.Name);
  </code></pre>
  
  <p>How can this be done?</p>