title: Entity Framework ObjectQuery order by date on many to many relation
body: <p>I have an <code>ObjectQuery</code> like that:</p>
  
  <pre><code>ObjectQuery&lt;Car&gt; query = GetCarQuery();
  </code></pre>
  
  <p>than i want to order by property <code>Date</code> on related entity <code>Race</code>, somehting like</p>
  
  <pre><code>query = (ObjectQuery&lt;Car&gt;)query.OrderBy(x=&gt; x.Races.Date); 
  query.Skip((page - 1) * rows).Take(rows).ToList();
  </code></pre>
  
  <p>was trying to go like that:</p>
  
  <pre><code>query = (ObjectQuery&lt;Car&gt;)query.OrderBy(i =&gt; i.Races.OrderBy(x=&gt; x.Date));
  query.Skip((page - 1) * rows).Take(rows).ToList(); //error here
  </code></pre>
  
  <p>and got an error when query executed </p>
  
  <pre><code>DbSortClause expressions must have a type that is order comparable.
  Parameter name: key
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>After reading that <a href="http://blogs.msdn.com/b/alexj/archive/2009/02/25/tip-1-sorting-relationships-in-entity-framework.aspx" rel="nofollow">http://blogs.msdn.com/b/alexj/archive/2009/02/25/tip-1-sorting-relationships-in-entity-framework.aspx</a> i go like this:</p>
  
  <pre><code>var result =  (from a in query
                          select new 
                   {
                       Car= a,
                       Race= a.Races.OrderBy(x =&gt; x.Date)
                   }).Skip((page - 1) * rows).Take(rows).ToList();
  </code></pre>
  
  <p>Didn't get any errors but sorting seams to be not working.</p>
  
  <p>One more try but with Entity SQL:</p>
  
  <pre><code> query = query.OrderBy("it.Races.Date");
   query = query.Skip((page - 1) * rows).Take(rows).ToList();//error here
  </code></pre>
  
  <p>and getting error: </p>
  
  <pre><code>'Date' is not a member of 'Transient.collection[Race(Nullable=True,DefaultValue=)]'. To extract a property of a collection element, use a subquery to iterate over the collection. Near simple identifier, line 6, column 28.
  </code></pre>
  
  <p>So i think I've tried everything i could...</p>