You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@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; }
}
The text was updated successfully, but these errors were encountered:
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; }
}
The text was updated successfully, but these errors were encountered: