Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Query user's role name using UserManager #634


User avatar
0
omar created

Is it possible to get the user's role name when quering for a user.

var user =   UserManager.Users.Where(e => e.Id == input.Id)
              .Select(a => new UserEditDto
               {
                    Id = a.Id,
                    FirstName = a.Name,
                    LastName = a.Surname,
                    Email = a.EmailAddress,
                    UserName = a.UserName,                  
                    RoleId = a.Roles.FirstOrDefault().RoleId // i would like Role's name instead
                })
               .FirstOrDefault();

Thanks


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    You need to write a LINQ join between User, UserRole and Role. Or seperately query role name by role id.