title: Create LINQ to entities OrderBy expression on the fly
body: <p>I'm trying to add the orderby expression on the fly. But when the query below is executed I get the following exception:</p>
  
  <blockquote>
    <p>System.NotSupportedException: Unable
    to create a constant value of type
    'Closure type'. Only primitive types
    ('such as Int32, String, and Guid')
    are supported in this context.</p>
  </blockquote>
  
  <p>The strange thing is, I am query exactly those primitive types only.</p>
  
  <pre><code>string sortBy = HttpContext.Current.Request.QueryString["sidx"];
  ParameterExpression prm = Expression.Parameter(typeof(buskerPosting), "posting");
  Expression orderByProperty = Expression.Property(prm, sortBy);
  
  // get the paged records
  IQueryable&lt;PostingListItemDto&gt; query =
     (from posting in be.buskerPosting
      where posting.buskerAccount.cmsMember.nodeId == m.Id
      orderby orderByProperty
      //orderby posting.Created 
      select new PostingListItemDto { Set = posting }).Skip&lt;PostingListItemDto&gt;((page -   1) * pageSize).Take&lt;PostingListItemDto&gt;(pageSize);
  </code></pre>
  
  <p>Hope somebody can shed some light on this!</p>