本文介绍了只能使用从.NET Core 2.0中的IdentityRole派生的角色来调用AddEntityFrameworkStores的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将项目从.NET Core 1.1更改为2.0版本,但是在尝试添加存储时,Identity出现错误:

I have changed a project from the .NET Core 1.1 to 2.0 version, but I'm getting an error from the Identity, when It tries to add the stores:

services.AddIdentity<ApplicationUser, IdentityRole<long>>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();

抛出的错误是:

这些是我的课程:

public class ApplicationUser : IdentityUser<long>
{
}

public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityRole<long>, long>        
{
        public ApplicationDbContext(DbContextOptions options) : base(options) { 
        }
}

有人可以帮助我吗?

推荐答案

自从我问了这个问题很久以来,但这就是我现在的处理方式:

Long time since I asked this question, but here's how I deal with nowadays:

Startup.cs

services.AddIdentity<User, Role>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddScoped<RoleManager<Role>>();

实体:

public class User : IdentityUser<int>
{
}

public class Role : IdentityRole<int>
{
}

这篇关于只能使用从.NET Core 2.0中的IdentityRole派生的角色来调用AddEntityFrameworkStores的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 10:23