C# ASP.NET Core UserManager查找不包含角色和删除来自角色失败

C# ASP.NET Core UserManager查找不包含角色和删除来自角色失败,c#,asp.net,entity-framework,asp.net-identity,C#,Asp.net,Entity Framework,Asp.net Identity,我想从角色中删除用户,但总是失败 我看到userManager.FindByIdasync()return的用户不包括角色。 但是我不能使用userManager.GetRolesAsync()获取所有角色信息 我将identityRole的PK从字符串更改为Guid并重命名为applicationRole,这是原因吗 应用程序用户 公共类应用程序用户:IdentityUser { } 公共类应用程序角色:IdentityRole { 私有应用程序角色() { } 公共应用程序角色(字符串ro

我想从角色中删除用户,但总是失败

我看到
userManager.FindByIdasync()
return的用户不包括角色。 但是我不能使用
userManager.GetRolesAsync()
获取所有角色信息

我将identityRole的PK从字符串更改为Guid并重命名为applicationRole,这是原因吗

应用程序用户

公共类应用程序用户:IdentityUser
{
}
公共类应用程序角色:IdentityRole
{
私有应用程序角色()
{
}
公共应用程序角色(字符串roleName):基本(roleName)
{
}
}
Startup.cs

services.AddIdentity()
.AddEntityFrameworkStores()
.AddDefaultTokenProviders();
应用程序上下文

public类ApplicationDbContext:IdentityDbContext{
公共应用程序DBContext(DbContextOptions选项)
:基本(选项)
{
}
模型创建时受保护的覆盖无效(ModelBuilder)
{
基于模型创建(生成器);
//定制
builder.Entity(i=>
{
i、 ToTable(“用户”);
i、 HasKey(x=>x.Id);
});
builder.Entity(i=>
{
i、 可转换(“角色”);
i、 HasKey(x=>x.Id);
});
}
}
为什么结果中不包括此用户的角色

当我试图调用
userManager.RemoveFromRoleAsync()
来删除用户表单角色时,什么也不会发生。不向数据库发送任何SQL查询,也不发生任何异常

是因为用户没有角色吗?还是其他问题

public class ApplicationUser : IdentityUser<Guid>
{
}

public class ApplicationRole : IdentityRole<Guid>
{
    private ApplicationRole()
    {
    }

    public ApplicationRole(string roleName) : base(roleName)
    {
    }
}
services.AddIdentity<ApplicationUser, ApplicationRole>()
            .AddEntityFrameworkStores<ApplicationDbContext, Guid>()
            .AddDefaultTokenProviders();
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, Guid> { 
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)
    {
    }
    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);
        // Customizations
        builder.Entity<ApplicationUser>(i =>
        {
            i.ToTable("Users");
            i.HasKey(x => x.Id);
        });
        builder.Entity<ApplicationRole>(i =>
        {
            i.ToTable("Roles");
            i.HasKey(x => x.Id);
        });
    }
}