OrderBy(propertyName) for complex types <p>I have </p> <pre><code>class User { public string Name {get; set; } } </code></pre> <p>and</p> <pre><code>class Example { public virtual User user {get; set; } } </code></pre> <p>they are 1..N relation and I'm using EF and that all works fine, but I want to do </p> <pre><code>var model = examples.OrderBy("user.Name"); </code></pre> <p>where examples is IQueryable of Examples and I get error that Example has no property of user.Name. Why is that? Can I specify my compare rules for class User? I tried implementing ICompare and IComparable with no success.</p> <p>EDIT: this is the extension for orderBy, how can I modify it to be able to use it for my example</p> <pre><code>public static IQueryable OrderBy(this IQueryable source, string propertyName) { var x = Expression.Parameter(source.ElementType, "x"); var selector = Expression.Lambda(Expression.PropertyOrField(x, propertyName), x); return source.Provider.CreateQuery( Expression.Call(typeof(Queryable), "OrderBy", new Type[] { source.ElementType, selector.Body.Type }, source.Expression, selector )); } } </code></pre>