在 asp.net 身份 2 中用于更改身份表名称的方法在 asp.net 身份 3 中不起作用。
最佳答案
您可以通过使用扩展方法 ToTable("TableName")
更改实体映射来轻松完成此操作。在 OnModelCreating
您的 DbContext
:
而且你不需要使用 .ForSqlServerToTable()
, 只是 .ToTable()
应该在任何数据库中工作。
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<User>().ToTable("Users"); // Your custom IdentityUser class
builder.Entity<IdentityUserLogin<string>>().ToTable("UserLogins");
builder.Entity<IdentityUserToken<string>>().ToTable("UserTokens");
builder.Entity<IdentityUserClaim<string>>().ToTable("UserClaims");
builder.Entity<IdentityUserRole<string>>().ToTable("UserRoles");
builder.Entity<IdentityRoleClaim<string>>().ToTable("RoleClaims");
builder.Entity<IdentityRole>().ToTable("Roles");
}
这里唯一的问题是记住使用具有标识符类型的泛型(字符串是 AspNetCore 上的默认值。
关于asp.net - 如何更改 asp.net identity 3 (vnext) 使用的表名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34523066/