Pages have Roles. Users have Roles. A user may only view a page if he and it share one or more roles.
This works:
Dim Allow As Boolean = False
CurrentPage.Roles.Load()
For Each r As Role In CurrentPage.Roles
r.Users.Load()
For Each u As User In r.Users
If u.Id = CurrentUser.Id Then
Allow = True
Exit For
End If
Next
If Allow Then
Exit For
End If
Next
I don't want to have to use nested loops if I can instead do it in fewer lines of code with LINQ or a lambda expression.
This always returns False:
Dim Allow As Boolean = (CurrentPage.Roles.ToList.Intersect(CurrentUser.Roles.ToList).Count > 0)
I think it fails because Roles are EntityObjects.
How can I make it compare only the Role Id values to determine equality?