我正在尝试完成对 .NET Core 2.0 的更新,但弹出了几个错误:
问题:
我有两个类,ApplicationRole 和 ApplicationUser,它们继承了 IdentityRole 和 IdentityUser 的一些属性。
随着 Core 2.0 的更新,我收到以下错误,声称找不到 IdentityRole 和 IdentityUser。
但是,包 Microsoft.AspNetCore.Identity.EntityFrameworkCore 2.0
安装在新版本的 .NET Core 中
关于 IdentityRole:
消息 1:
The type or namespace name 'IdentityRole' could not be found (is it missing a using directive or an assembly reference?)
消息 2:
The 'Application.Models.ApplicationRole' type can not be used as a parameter of type 'TRole' in the generic type or method 'IdentityDbContext '. There is no implicit reference conversion from 'Application.Models.ApplicationRole' to 'Microsoft.AspNetCore.Identity.IdentityRole '.
ApplicationRole 的定义:
public class ApplicationRole:IdentityRole
{
public string Description { get; set; }
public DateTime CreatedDated { get; set; }
public string IPAddress { get; set; }
}
关于 IdentityUser:
消息 1:
The type or namespace name 'IdentityUser' could not be found (is it missing a using directive or an assembly reference?)
消息 2:
The 'Application.Models.ApplicationUser' type can not be used as a parameter of type 'TUser' in the generic type or method 'IdentityDbContext '. There is no implicit reference conversion from 'Application.Models.ApplicationUser' to 'Microsoft.AspNetCore.Identity.IdentityUser '.
ApplicationUser 的定义
public class ApplicationUser:IdentityUser
{
public string Name { get; set; }
}
定义此类及其用法的指南如下:
随着 Core 2.0 的改变,我想知道 IdentityRole 和 IdentityUser 是如何改变的,所以我不能再继承它们。
最佳答案
已解决。
保留这些类的包 Microsoft.AspNetCore.Identity.EntityFrameworkCore
已更改。要访问这些类(IdentityUser
和 IdentityRole
),必须添加
using Microsoft.AspNetCore.Identity;
有了这个,问题就解决了。
关于c# - 无法从 ASP.NET Core 2.0 中的 IdentityUser 和 IdentityRole 继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45830479/