title: Dynamic Linq - Setting orderby expression type at runtime
body: <p>I'm using dynamic Linq and have the where clauses working. Now I'm looking to add orderby clauses but am having a problem being able to set the type of the dynamic expression. Below is working code that I have:</p>
  
  <pre><code>class MyClass {
      public string Owner;
      public DateTime Inserted;
  }
  
  Expression&lt;Func&lt;MyClass, bool&gt;&gt; whereExpression = DynamicExpression.ParseLambda&lt;MyClass, bool&gt;("owner = \"joe\"");
  Expression&lt;Func&lt;MyClass, DateTime&gt;&gt; orderExpression = DynamicExpression.ParseLambda&lt;MyClass, DateTime&gt;("inserted");
  var result = from item in table.Where(whereExpression).OrderBy(orderExpression) select item;
  result.ToList().ForEach(m =&gt; Console.WriteLine("inserted=" + m.Inserted + "."));
  </code></pre>
  
  <p>Because I need to use different properties in the orderby expression what I'd like to be able to do is use something like the code below which is not working.</p>
  
  <pre><code>Expression&lt;Func&lt;MyClass, bool&gt;&gt; whereExpression = DynamicExpression.ParseLambda&lt;MyClass, bool&gt;("owner = \"joe\"");
  Type orderType = typeof(DateTime);
  Expression&lt;Func&lt;MyClass, orderType&gt;&gt; orderExpression = DynamicExpression.ParseLambda&lt;MyClass, orderType&gt;("inserted");
  var result = from item in table.Where(whereExpression).OrderBy(orderExpression) select item;
  result.ToList().ForEach(m =&gt; Console.WriteLine("inserted=" + m.Inserted + "."));
  </code></pre>
  
  <p>The compiler isn't happy with the line delcaring the orderExpression. Is there any way to set the type of a Func at runtime?</p>