title: Linq sort child in query
body: <p>I have an EF model as follows:</p>
  
  <p><img src="https://i.stack.imgur.com/zhVs9.png" alt="enter image description here"></p>
  
  <p>On this model, I can obviously use <code>Categories.Products</code> to receive a list of products.</p>
  
  <p>I have a query as follows to return a list of Categories, with Products as a List to be used in an ASP.NET MVC 3 view:</p>
  
  <pre><code>var categories = (from a in context.Categories.Include("Products")
                    orderby a.SortOrder ascending
                    select a).ToList();
  return View(categories);
  </code></pre>
  
  <p>In order to show the Products in order of their SortOrder I currently have to do:</p>
  
  <pre><code>&lt;ul&gt;
  @foreach (var category in Model)
  {
      &lt;li&gt;@category.Title
          &lt;ul&gt;
          @foreach (var product in category.Products.OrderBy(a =&gt; a.SortOrder))
          {
              &lt;li&gt;@product.Description&lt;/li&gt;
          }
          &lt;/ul&gt;
      &lt;/li&gt;
  }
  &lt;/ul&gt;
  </code></pre>
  
  <p>The offending line is: <code>@foreach (var product in category.Products.OrderBy(a =&gt; a.SortOrder))</code> as this is handling a bit of my model in the view.</p>
  
  <p>Is there a way to sort this in the query?</p>