Question

I have a Pages table, I have a PagesRoles table with PageId, RoleID that links to ASP.Net Membership Roles table and the Pages table.

I want to somehow return a Page that links to the currently logged in User's Roles.

The User may be in more than one role. A Page can have more than one Role against it.

I have a Page class that has a foreign key property of IQueryable. PageRoles has a IQueryable to ASPNet Roles table (IQueryable) and IQueryable

Thanks

EDIT:

Using Adam's answer to get all Pages that have a role assigned to it which matches one of the currently logged in user's roles I have a added issue. I have a Menu table that has a PageID foreign key and a CategoryID.

I would like to return all Menu items with a CategoryID of 4. For those that have a PageID I need to make sure that the user is allowed to see that Page based on his role. I think Adam's query would do that. So I think what I need is a UNION, return all Menu items where PageID is null and CategoryID is 4 and return all Menu items where CategoryID is 4 and join to the Page->PageRole->ASPNetRole where current users roles is in that ASPNetRole results.

Was it helpful?

Solution

If you're using SubSonic 3 a query like the following should work:

var pagesForUser = from pages in Pages.All()
    join pagesRoles in PagesRoles.All() on pages.Id equals pagesRoles.PageID
    join roles in Roles.All() on pagesRoles.RoleId equals roles.Id
    where User.GetRoles().Contains(roles.Name)
  select pages;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top