Kumar
Kumar

Reputation: 2863

Many to Many LINQ TO SQL Query

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?

Upvotes: 1

Views: 187

Answers (1)

Brian Mains
Brian Mains

Reputation: 50728

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

Upvotes: 1

Related Questions