views:

59

answers:

2

I have the following tables:

Users
Roles
UserRoles
MenuItems
RoleMenuItems

A User can have multiple Roles and a MenuItem can be accessed by multiple Roles. Now I want to write a method as follows:

public IList<MenuItems> GetMenuItems(UserRoles userRoles)
{
   var menus = // LINQ query to get the MenuItems by UserRoles 

   return menus.ToList();
}

Is there a way to do this?

+1  A: 

userRoles.SelectMany(i => i.MenuItems);

Brian
A: 
var menus =
    from roleMenuItem in userRoles.RoleMenuItems
    from menuItem in roleMenuItem.MenuItems
    select menuItem;
Steven