title: Access nested properties with dynamic lambda using Linq.Expression
body: <p>Let's assume that I have two classes:</p>
  
  <pre><code>class person
  {
      int ID
      string name
      Address address
  }
  class address
  {
      int ID
      string street
      string country
  }
  </code></pre>
  
  <p>These classes are more or less given, they are mapped via nHibernate to be honest :)</p>
  
  <p>In a grid (<a href="http://www.datatables.net" rel="noreferrer">datatables.net</a> as base) I would like to have a type-independent sorting.</p>
  
  <p>Therefore I created a lambda expression:</p>
  
  <pre><code>  var param = Expression.Parameter(typeof(T), typeof(T).Name);
    var sortExpression = Expression.Lambda&lt;Func&lt;T, object&gt;&gt;
                                (Expression.Convert(Expression.Property(param, "Property to sort"), typeof(object)), param);
  </code></pre>
  
  <p>If I pass Person as Type T and replace the "Property to sort" with "name" it works fine (creates a correct lambda). If the Property to sort is "address.street" it won't work, throw me the following error:</p>
  
  <pre><code>Property 'address.street' is not defined for type 'person'
  </code></pre>
  
  <p>I see only one solution so far, but not clear enough... I would try to split the string which contains the Property-Name (split by .) </p>
  
  <p>Can anyone give a better solution? I need to add the sortExpression to an IQueryable object <code>query.OrderBy(sortExpression)</code>.</p>
  
  <p>Not sure if my title is clear, please go ahead and correct it.</p>
  
  <p>Thanks in advance.</p>