title: How does nesting an OrderBy in a Dynamic Linq query work?
body: <p>I'm using Dynamic Linq and today I wanted to build a slightly more complex nested query:</p>
  
  <pre><code>"Composition
  .Where(((ExpirationDate &gt; DateTime.UtcNow.Date) &amp;&amp; (ExpirationDate.Year != 9999)))
  .OrderBy(\"ExpirationDate ASC\")
  .Select(ExpirationDate)
  .FirstOrDefault() == @0"
  </code></pre>
  
  <p>(the breaks are only there for readability in this post, not really there in code)</p>
  
  <p>The query is held by a string variable and passed to this:</p>
  
  <pre><code>private static Func&lt;IQueryable&lt;T&gt;, object, IQueryable&lt;T&gt;&gt; CreateWhereExpression&lt;T&gt;(string whereClause) where T : class
  {
       return (q, o) =&gt; q.Where(whereClause, o);
  }
  </code></pre>
  
  <p>Which happily creates the Where expression. (note that whereClause contains the exact string above "Composition.Where....")
  But as soon as it's time to execute, it will complain:</p>
  
  <blockquote>
    <p>No applicable aggregate method 'OrderBy' exists</p>
  </blockquote>
  
  <p>So my question is, what am I doing wrong? How can I get the nested OrderBy to work?</p>