There are three tables which are related to roles.
- AspNetUsers - keeps the
UserId
data - AspNetRoles - keeps the
RoleName
andRoleId
- AspNetUserRoles - makes a relation through AspNetUsers and AspNetRoles. It has only two cloumns which are
UserId
andRoleId
. But for some reason I couldn't access to this table directly (likedb.UserRoles
).
So what I'am trying to do is avoid listing the users which are in the Admin role.
My code is like this:
return View(db.Users.OrderBy(e => e.UserName)
.ToPagedList(pageNumber, pageSize));
I think I should make something like this but I always get errors when I do it this way
return View(db.Users.Where(e => e.Roles.Where(r => r.RoleId != "1"))
.OrderBy(e => e.UserName)
.ToPagedList(pageNumber, pageSize));
// suppose that the RoleId of Admin is 1