title: Linq OrderBy with an expression variable
body: <p>I'm trying to figure out how to sort by a variable, not a string.
  I believe I should be able to represent <code>x =&gt; x.SomeProperty</code> and save that to a variable and pass it into the <code>OrderBy</code> method but can't figure out what to use here.</p>
  <pre><code>SomeType sortExpr = null;
  switch(sortByColumnName)
  {
      case &quot;Name&quot;:
          sortExpr = x =&gt; x.Name
          break;
      case &quot;Age&quot;:
          sortExpr = x =&gt; x.Age
          break;
      case &quot;OtherThing&quot;:
          sortExpr = x =&gt; x.OtherReference.Name
          break;
  }
  
  if (sortDirection == &quot;asc&quot;)
      query = query.OrderBy(sortExpr);
  else
      query = query.OrderByDescending(sortExpr);
  </code></pre>