AddEntityFrameworkStores 只能使用派生自 .NET Core 2.0 中的 IdentityRole 的角色调用 [英] AddEntityFrameworkStores can only be called with a role that derives from IdentityRole in .NET Core 2.0

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

问题描述

我已将一个项目从 .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();

抛出的错误是:

AddEntityFrameworkStores 只能使用派生的角色调用来自身份角色

AddEntityFrameworkStores can only be called with a role that derives from IdentityRole

这些是我的课程:

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>
{
}

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆