lucas
lucas

Reputation: 4685

How to prefix .Net Core Identity tables

Is there a way to prefix .Net Core Identity tables, instead of 'AspNetUsers' being created as a database name, I would like to end up with 'ProjectName_AspNetUsers'

Upvotes: 1

Views: 1138

Answers (1)

lucas
lucas

Reputation: 4685

Finally, in case you will look for the solution, here is how I mange to accomplish that in ASP.NET Core:

ApplicationDbContext.cs:

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        builder.Entity<ApplicationUser>().ToTable("ProjectName_Users");
        builder.Entity<IdentityUserRole<string>>().ToTable("ProjectName_UserRoles");
        builder.Entity<IdentityUserLogin<string>>().ToTable("ProjectName_UserLogins");
        builder.Entity<IdentityUserClaim<string>>().ToTable("ProjectName_UserClaims");
        builder.Entity<IdentityRole>().ToTable("ProjectName_Roles");
        builder.Entity<IdentityRoleClaim<string>>().ToTable("ProjectName_AspNetRoleClaims");
        builder.Entity<IdentityUserToken<string>>().ToTable("ProjectName__AspNetUserTokens");
    }

Upvotes: 10

Related Questions