我正在尝试在我的 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");
根本不起作用。
ApplicationUser 和 ApplicationUserClaim 都是干净的类,如下所示:
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/