AddEntityFrameworkStores只能使用从.NET Core 2.0中的IdentityRole派生的角色调用

Fel*_*ana 11 asp.net-identity asp.net-core-mvc .net-core asp.net-core-2.0

我已经将项目从.NET Core 1.1更改为2.0版本,但是当它尝试添加商店时,我从Identity中收到错误:

services.AddIdentity<ApplicationUser, IdentityRole<long>>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
Run Code Online (Sandbox Code Playgroud)

抛出的错误是:

只能使用派生自IdentityRole的角色调用AddEntityFrameworkStores

这些是我的课程:

public class ApplicationUser : IdentityUser<long>
{
}

public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityRole<long>, long>        
{
        public ApplicationDbContext(DbContextOptions options) : base(options) { 
        }
}
Run Code Online (Sandbox Code Playgroud)

有人可以帮帮我吗?

Fel*_*ana 7

很久没有问这个问题了,但现在我是这样处理的:

启动文件

services.AddIdentity<User, Role>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddScoped<RoleManager<Role>>();
Run Code Online (Sandbox Code Playgroud)

实体:

public class User : IdentityUser<int>
{
}

public class Role : IdentityRole<int>
{
}
Run Code Online (Sandbox Code Playgroud)


小智 5

对于同样的问题,你可以看看这个:https : //github.com/aspnet/Identity/issues/1364