覆盖默认标识表名 [英] Override Default Identity Table Names
本文介绍了覆盖默认标识表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想重命名默认标识表名称:
I would like to rename the default identity table names:
- AspNetRoles
- AspNetUserClaims
- AspNetUserLogins
- AspNetUserRoles
- AspNetUsers
我知道如何做到这一点使用EF6:
I understand how to do this using EF6:
protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<IdentityUser>()
.ToTable("Users", "dbo").Property(p => p.Id).HasColumnName("User_Id");
modelBuilder.Entity<User>()
.ToTable("Users", "dbo").Property(p => p.Id).HasColumnName("User_Id");
}
不过我与EF7挣扎的DbModelBuilder已经换成了模型构建器。有什么建议?
However I'm struggling with EF7 as the DbModelBuilder has been replaced with ModelBuilder. Any suggestions?
推荐答案
您必须使用ForSqlServer或ForRelational在SqlServerPropertyBuilder更改列名,并在模型构建器来更改表名称
You must use ForSqlServer or ForRelational in the SqlServerPropertyBuilder to change the column name and in the modelBuilder to change the table name
modelBuilder.Entity<IdentityUser>()
.Property(o => o.Id)
.ForSqlServer()
.Column("User_Id")
modelBuilder.Entity<IdentityUser>()
.ForSqlServer()
.Table("User")
更新:
对于测试5不再强制使用ForSqlServer
Update : For the beta 5 is not longer mandatory to use ForSqlServer
这篇关于覆盖默认标识表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文