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