title: EntityFramework 4 OrderBy overwrites previous OrderBy calls
body: <p>I often want to provide orderings for IQueryables that should act like secondary orderings if another is specified later.  For example, the following:</p>
  
  <pre><code>Repository.All.OrderBy(o =&gt; o.Name).OrderBy(o =&gt; o.SerialNumber)  [A]
  </code></pre>
  
  <p>Should be equivalent to:</p>
  
  <pre><code>Repository.All.OrderBy(o =&gt; o.SerialNumber).ThenBy(o =&gt; o.Name)
  </code></pre>
  
  <p>This worked correctly using LINQ to SQL.  However, in EntityFramework 4, the Order-By clause in the generated SQL looks like this:</p>
  
  <pre><code>ORDER BY [Project1].[SerialNumber] ASC
  </code></pre>
  
  <p>It completely ignores the first OrderBy statement, which actually breaks OrderBy being a stable sort.  ThenBy is not an option for me, because the orderings are not always defined in the same place (for example, in statement <code>[A]</code> above, the <code>OrderBy(o =&gt; o.Name)</code> could be defined in the Repository.  Extensions to <code>IQueryable&lt;TModel&gt;</code> are not a good solution either, because it doesn't allow different Repositories to sort differently, and the consuming code should not have to call some <code>.SortDefault()</code> code since that's not its concern.</p>
  
  <p>Is there any good way to force Linq to Entities to respect multiple OrderBy statements?</p>
  
  <p>Thanks</p>