I trying to retrieve multiple users, including their role(s). This is used in a forum, where I want to show the role(s) of users who commented on the thread. I've seen many examples of retrieving the roles for a single IdentityUser
using the UserManager
and RoleManager
, but as mentioned, I have multiple users I wish to retrieve.
I've tried including the roles as a property on the user, like so:
public virtual ICollection<IdentityUserRole<string>> Roles { get; set; }
But this doesn't seem to work. I tried skipping the many-to-many table, and simply include the role entity directly on my user, like this:
public virtual ICollection<IdentityRole> Roles { get; set; }
No difference either, still doesn't work. Basically I just want to join the roles to the user, but I'm not sure how.
Including the IdentityUserRole<string>
property, and retrieving my users, gives me the following error:
Unknown column 'x.UserProfile.Roles.UserId1' in 'field list'
Here's my select:
comments = _context.Comments
.Include(x => x.UserProfile)
.Include(x => x.UserProfile.Roles)
.OrderBy(x => x.CreateDate)
.Where(x => x.ThreadId == id && !user.IgnoredUsers.Contains(x.UserProfile.UserName))
.ToPagedList(Constants.PAGER_DEFAULT_SMALL, page);