ASP.Net Core-如何将新字段添加到默认的Microsoft Identity结构中



使用ASP。Net Core 2.1中,我正试图向默认的Microsoft Identity Users表结构中添加一个新字段,因此我创建了一个新模型,用于项目数据库上下文以继承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; }
}

这是输出错误:

非泛型类型"IdentityDbContext"不能与类型参数一起使用

我做错了什么?

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

请参阅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>

最新更新