c# - 如何使用 ASP.NET Core 以及 EF 和 Identity 在 MySQL 中创建自定义 UserClaims 表?

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

我正在尝试在我的 MySQL 数据库中实现 ASP.NET Core Identity。我想将声明保存在名为与“aspnetuserclaims”不同的表中。我设法在 MyContext 中的 OnModelCreating() 方法中使用此方法为用户指向自定义表,该方法继承自 IdentityDbContext 类:

 modelBuilder.Entity<ApplicationUser>().ToTable("users").Property(p => p.Id).HasColumnName("Id");

但是,当我想对继承表单 IdentityUserClaim 的类执行相同操作时,使用:

modelBuilder.Entity<ApplicationUserClaim>().ToTable("userclaims").Property(p => p.Id).HasColumnName("Id");

根本不起作用。

ApplicationUserApplicationUserClaim 都是干净的类,如下所示:

  public class ApplicationUser : IdentityUser<string> {}

异常(exception):

MySqlException: Table 'dbname.aspnetuserclaims' doesn't exist

最佳答案

IdentityUser具有泛型类型重载。您正在使用IdentityUser<TKey> ,但是如果你想自定义像声明类这样的东西,你需要指定 IdentityUser<TKey,TUserClaim,TUserRole,TUserLogin> .

此外,IdentityDbContext也有泛型类型重载,因此同样,您需要确保在那里使用正确的重载,即: IdentityDbContext<TUser,TRole,TKey,TUserClaim,TUserRole,TUserLogin,TRoleClaim,TUserToken> .

关于c# - 如何使用 ASP.NET Core 以及 EF 和 Identity 在 MySQL 中创建自定义 UserClaims 表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50697366/

相关文章:

c# - 在 C# 中创建一个空的 BitmapSource

Mysql:选择未分配的记录,例如到特定群体

mysql - mysql字符集问题

mysql - Pomelo MySQL (.NET Core) 数据库故障后无法恢复

c# - 将 Xamarin iOS UI 项目链接到 Visual Studio 项目

c# - 协程函数在 WaitForSeconds 处停止

c# - 'private extern String PadHelper'的源代码在哪里

mysql - 从表中选择每个重复 ID 的用户

c# - 如何在 ASP.NET Core Web API 应用程序中创建全局变量?

c# - ASP.NET Core Web API 身份验证