Closed sajidali2444 closed 3 years ago
I think you are at the right path, you need to have have access to all identity schema and then include UserRole and Role, like in your example and then project that to your custom view model to include all roles. This link explains how to access all this schema:
@asadsahi Hi, A quick question may be helpful to others. Is it possible with your current code base we can get all users with associated roles? If you provide me a code sample or help really thankful to you. when i try to join user with roles there is no roles property and if i add this property then its not return roles. here is my code can you help me . var users = _userManager.Users.Include(u => u.UserRoles).ThenInclude(ur => ur.Role).ToList();
public class ApplicationUser : IdentityUser
{
public int UserId { get; set; }
public ICollection UserRoles { get; set; }
}
public class ApplicationRole : IdentityRole
{
[StringLength(100)]
public string Description { get; set; }
public ICollection UserRoles { get; set; }
}
public class ApplicationUserRole : IdentityUserRole
{
//public int Id{get;set;}
public virtual ApplicationUser User { get; set; }
public virtual ApplicationRole Role { get; set; }
}