3

I needed to add a List property to IdentityRole in order to establish a Many-to-Many relationship. After doing this and running code-first migration, everything seemed fine. However now when I try and pull roles for a user, the result is always empty even though I can see they exist in the DB. Any idea why this may be happening?

public class Role : IdentityRole
{
    public Role(string name) : base(name) { }
    public List<FeatureRole> FeatureRoles { get; set; }
}
public class FeatureRole
{
    public int FeatureId { get; set; }
    public Feature Feature { get; set; }
    public string RoleId { get; set; }
    public Role Role { get; set; }
}
public class Feature
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Url { get; set; }
    public Permission AvailablePermissions { get; set; }
    public Permission Permissions { get; set; }
    public bool IsSystem { get; set; }
    public List<FeatureRole> FeatureRoles { get; set; }
}
public async Task<CurrentUserJS> AuthenticateAsync(string username, string password)
{
    try
    {
        var user = await _userManager.FindByNameAsync(username);
        if(user != null)
        {
            var signInResult = await _signInManager.PasswordSignInAsync(user, password, false, false);
            if(signInResult.Succeeded)
            {
                var roles = await _userManager.GetRolesAsync(user); // <-- roles = [] always

                //....

}
roonz11
  • 795
  • 1
  • 13
  • 24

0 Answers0