title: Unable to cast the type 'System.String' to type 'System.Object'. LINQ to Entities only supports casting Entity Data Model primitive types
body: <p>I am using EF 4 but it is giving me error when I try to order my list. </p>
  
  <pre><code>Unable to cast the type 'System.String' to type 'System.Object'. LINQ to Entities only supports casting Entity Data Model primitive types.
  </code></pre>
  
  <p>This is my code to get the experssion by entering the property name, example below get the Customer Name</p>
  
  <pre><code>var param = Expression.Parameter(typeof(Customer), "N");
  
  var sortExpression = Expression.Lambda&lt;Func&lt;T, object&gt;&gt;
              (Expression.Convert(Expression.Property(param, "Name"), typeof(object)), param);
  </code></pre>
  
  <p>And my EF code is </p>
  
  <pre><code>GetObjectSet&lt;T&gt;().AsQueryable().OrderBy(sortExpression).Skip(0).Take(5);
  </code></pre>
  
  <p>I know it is some sort of casting problem with EF because it works without the EF but it gives me this error when i hook it up with EF. Is there a work around or something because i don't want to use LINQ.</p>