如何在Asp.net Identity 3.0中更改表名称? [英] How to change table names in Asp.net Identity 3.0?
本文介绍了如何在Asp.net Identity 3.0中更改表名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在ASP.net Identity 3.0中更改表名?
How to change table names in ASP.net Identity 3.0?
我已经搜索过,但没有得到有关Identity 3.0的任何可行的书面记录
I have searched but I didn't get any workable write up for Identity 3.0
和此如何更改asp.net身份3(vnext)使用的表名?不起作用.
推荐答案
您可以通过使用DbContext
的OnModelCreating
上的扩展方法ToTable("TableName")
更改实体映射来轻松实现此目的:
You can do this easily by changing the entity mapping with extension method ToTable("TableName")
on OnModelCreating
of your DbContext
:
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上的字符串是默认值.
The only catch here is to remember to use the generics with the type of your identifier (string is default on AspNetCore.
这篇关于如何在Asp.net Identity 3.0中更改表名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文