ASP.Net 核心 - 如何将新字段添加到默认的 Microsoft 身份结构

ASP.Net Core - How to add a new field to the default Microsoft Identity structure

使用 ASP.Net Core 2.1,我试图向默认的 Microsoft Identity Users table 结构添加一个新字段,因此我创建了一个在项目数据库上下文中使用的新模型继承自Microsoft.AspNetCore.Identity,我之前成功实现了下面的代码,但是这次报错了。

这是模型:

public class ApplicationUser : IdentityUser
{
    public string Age { get; set; }
}

这是数据库上下文:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser, string>
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
    public string CurrentUserId { get; set; }
}

这是输出错误:

The non-generic type 'IdentityDbContext' cannot be used with type arguments

我做错了什么?

我不确定,但我没有看到接受这两种类型参数的基本构造函数。

MSDN

有效的类型参数是:

//none
public class IdentityDbContext

//application user
public class IdentityDbContext<TUser> 

//Thanks to @ Ivvan
public class IdentityDbContext<TUser,TRole,TKey>

//the full version
public class IdentityDbContext<TUser, TRole, TKey, TUserLogin, TUserRole, TUserClaim>

所以在你的情况下,我认为你的意思是:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>