c# - ASP.Net Core - 如何向默认 Microsoft 标识结构添加新字段
问题描述
使用 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”不能与类型参数一起使用
我在这里做错了什么?
解决方案
我不确定,但我没有看到接受这 2 个类型参数的基本构造函数。
见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>
推荐阅读
- java - @TransactionScoped 和钝化
- asp.net-mvc - 如何从我的 mvc 项目中捕获 badrequest() 消息
- android - 构建应用程序时出现 CLDRLocaleDataMetaInfo 错误问题
- kubernetes - 如何为 Prometheus pod scrape 指定凭据
- reactjs - 如何使用 react-testing-library 和 jest 来模拟自定义反应钩子更新?
- python - 如何在python datetime中删除零
- sql - 如何交叉连接但在 BIGQUERY 中使用最新值
- react-native - react-native android不会在设备上运行
- youtube-api - 为什么在使用实时聊天 API 时出现页面令牌错误?
- flutter - 如何在图像右侧添加颤动单选按钮