title: Generate EF orderby expression by string
body: <p>I want to generate expression by string parameter,some code like:</p>
  
  <pre><code>private Expression&lt;Func&lt;Task, T&gt;&gt; Generate(string orderby)
  {
      switch (orderby)
      {
          case "Time":  
              return t =&gt; t.Time;
          case "Money":
              return t =&gt; t.RewardMoney;
          default:
              return t =&gt; t.Id;
      }
  }
  </code></pre>
  
  <p>then call it:</p>
  
  <pre><code>_context.Items.OrderBy(Generate("Money"));
  </code></pre>
  
  <p>But It can't compile! I change T to object.</p>
  
  <pre><code>private Expression&lt;Func&lt;Task, object&gt;&gt; Generate(string orderby)
  </code></pre>
  
  <p>Then It can compile, but It doesn't work.</p>
  
  <blockquote>
    <p>System.NotSupportedException: Unable to cast the type 'System.Int32' to type 'System.Object'. LINQ to Entities only supports casting EDM primitive or enumeration types.</p>
  </blockquote>