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

2019-07-24 08:14发布

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条回答
相关推荐>>
2楼-- · 2019-07-24 08:55

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.

查看更多
登录 后发表回答