【发布时间】:2017-10-25 11:58:54
【问题描述】:
我正在尝试自定义 Identity,但在尝试让我的 DbContextClass 从 IdentityUser 继承时遇到以下错误:
严重性代码描述项目文件行抑制状态 错误 CS0311 类型“CustomerManager.Domain.User”不能用作泛型类型或方法“IdentityDbContext”中的类型参数“TUser”。没有从“CustomerManager.Domain.User”到“Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser”的隐式引用转换。 CustomerManager.Data E:\Clients\DMFA\CustomerManager\CustomerManager.Data\CustomerManagerContext.cs 9 活动
用户类:
public class User : IdentityUser<long, UserLogin, UserRole, UserClaim>
{
public string FirstName { get; set; }
public string LastNme { get; set; }
}
DbContext 类:
public class CustomerManagerContext : IdentityDbContext<User>
{
public CustomerManagerContext(DbContextOptions<CustomerManagerContext> options) : base(options)
{
}
}
UserLogin 类:
public class UserLogin : IdentityUserLogin<long>
{
}
用户角色类:
public class UserRole : IdentityUserRole<long>
{
}
UserClaim 类:
public class UserClaim : IdentityUserClaim<long>
{
}
尽管我认为是正确的,但我在 DbContext 类中得到了上述错误。
我错过了什么?
【问题讨论】:
-
为什么你的
IdentityUser上面有<long, UserLogin, UserRole, UserClaim>的所有属性?我认为你不需要所有这些。 -
@NovaDev 查看 PankajKapare 答案
-
您可能希望从更简单的开始,然后逐步提高复杂性。您指向的以下答案并未回答有关您为什么要以这种方式添加这些属性的问题...
-
@NovaDev 你是绝对正确的。回答问题以获得您的信用。
标签: c# asp.net-core asp.net-identity