Renaming dbo.AspNetUsers table

asp.net asp.net-identity entity-framework

Accepted Answer

The database needs to be updated.Enable-Migrations and Update-Database detailed explanation, here. Writing our model classes and configurations is the goal of the EF code first method, and if we make changes, we use EF migrations to update the database schema.

Zzz-19 and Zzz-23 explain the database-first technique using the Asp.net Identity Entity Framework, which is not exactly simple.

4
5/23/2017 12:10:22 PM

Popular Answer

Enter the code below in IdentityModels.cs.

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DBConnectionString", throwIfV1Schema: false)
    {
    }

    protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims");
        modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles");
        modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogins");
        modelBuilder.Entity<IdentityRole>().ToTable("Roles");
        modelBuilder.Entity<ApplicationUser>().ToTable("Users");
    }

    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }
}

Write the following code in the Global.asax.cs file's Application Start() method.

Database.SetInitializer<ApplicationDbContext>(null);


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow