How to change table names in Asp.net Identity 3.0?

孤街浪徒 提交于 2019-12-13 01:12:04

问题


How to change table names in ASP.net Identity 3.0?

I have searched but I didn't get any workable write up for Identity 3.0

and this How can I change the table names used by asp.net identity 3 (vnext)? is not working.


回答1:


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");            
}

The only catch here is to remember to use the generics with the type of your identifier (string is default on AspNetCore.



来源:https://stackoverflow.com/questions/36589980/how-to-change-table-names-in-asp-net-identity-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!