title: LINQ to SQL, sorting by a related table
body: <p>I'm trying to order the values in a related table using <a href="http://en.wikipedia.org/wiki/Language_Integrated_Query#LINQ_to_SQL" rel="nofollow noreferrer">LINQ to SQL</a>.</p>
  
  <p>I have 2 tables. Menu and MenuSection. They are related one to many on Menu.MenuId == MenuSection.MenuId</p>
  
  <p>Currently, I'm pulling this information using the following query</p>
  
  <pre><code>var menus = from m in _context.Menus                        
                      select m;
  </code></pre>
  
  <p>This gets fed into an <a href="http://en.wikipedia.org/wiki/ASP.NET_MVC_Framework" rel="nofollow noreferrer">ASP.NET MVC</a> page and works fine.</p>
  
  <p>I'd like to be able to sort the data the column MenuSection.Order</p>
  
  <p>I've tried doing this:</p>
  
  <pre><code>var menus = from m in _context.Menus 
                  join ms in _context.MenuSections on m.MenuId equals ms.MenuId
                  orderby ms.Order ascending select m;
  </code></pre>
  
  <p>But it's bringing back a set of data that is incorrect. It displays repeated Menu information.</p>
  
  <p>EDIT: To clarify what i'm expecting the data shoud be:</p>
  
  <p>There are x Menu's in Menu.</p>
  
  <p>Each Menu has many MenuSection's</p>
  
  <p>I'd like to list out each Menu and their related MenuSection.
  The MenuSections need to be in order based on MenuSection.Order</p>
  
  <pre><code>Menu 1
  - MenuSection 1, Order = 1
  - MenuSection 3, Order = 2
  Menu 2
  - MenuSection 4, Order = 1
  - MenuSection 2, Order = 2
  </code></pre>