为.NetCore定制标识

时间:2017-05-25 00:02:04

标签: c# asp.net-core asp.net-identity

我正在尝试自定义身份,并且在尝试让我的DbContextClass继承自IdentityUser时出现以下错误:

  

严重级代码描述项目文件行抑制状态   错误CS0311类型' CustomerManager.Domain.User'不能用作类型参数' TUser'在泛型类型或方法中#IdentityDbContext'来自' CustomerManager.Domain.User'没有隐式参考转换。到' Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser'。 CustomerManager.Data E:\ Clients \ DMFA \ CustomerManager \ CustomerManager.Data \ CustomerManagerContext.cs 9 Active

用户类:

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

UserRole类:

public class UserRole : IdentityUserRole<long>
{
}

UserClaim类:

public class UserClaim : IdentityUserClaim<long>
{
}

尽管我认为是正确的,但我在DbContext类中遇到了上述错误。

enter image description here

我错过了什么?

2 个答案:

答案 0 :(得分:2)

您可能希望开始更简单,然后以更复杂的方式工作。我希望这有帮助!

public class User : IdentityUser<long>
{
    public string FirstName { get; set; }
    public string LastNme { get; set; }
}

答案 1 :(得分:0)

由于您已自定义用户和角色您的CustomerManagementContext定义应如下所示。

public class CustomerManagementContext  : IdentityDbContext<User, IdentityRole<long>, long, UserLogin,UserRole,UserClaim>{}