-1

I copied default AspNet Identity tables (AspNetUsers, AspNetLogin etc) into my database and everything worked fine. Then I changed their names and made my own context with the following method:

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

        modelBuilder.Entity<IdentityUser>()
            .ToTable("tblUsers", "dbo");

        modelBuilder.Entity<IdentityRole>()
            .ToTable("tblRoles", "dbo");

        modelBuilder.Entity<IdentityUserRole>()
            .ToTable("tblUserRoles", "dbo");

        modelBuilder.Entity<IdentityUserClaim>()
            .ToTable("tblUserClaims", "dbo");

        modelBuilder.Entity<IdentityUserLogin>()
            .ToTable("tblUserLogins", "dbo");
    }

But it seems like the application is still looking for tables with old names as I'm getting error:

enter image description here

Please, tip me what are the neccessary changes that I haven't done ?

1
  • did you used the migration to update the database? Commented Oct 25, 2016 at 16:11

1 Answer 1

0

According to How can I change the table names when using Visual Studio 2013 ASP.NET Identity? this should work:

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

    modelBuilder.Entity<IdentityUser>().ToTable("MyUsers").Property(p => p.Id).HasColumnName("UserId");
    modelBuilder.Entity<ApplicationUser>().ToTable("MyUsers").Property(p => p.Id).HasColumnName("UserId");
    modelBuilder.Entity<IdentityUserRole>().ToTable("MyUserRoles");
    modelBuilder.Entity<IdentityUserLogin>().ToTable("MyUserLogins");
    modelBuilder.Entity<IdentityUserClaim>().ToTable("MyUserClaims");
    modelBuilder.Entity<IdentityRole>().ToTable("MyRoles");
}

also make sure you're not falling into a trap that ASP.NET Identity uses its default aspnetdb.mdf database and check your web.config for something like this:

<connectionStrings>
   <remove name="LocalSqlServer" />
   <add connectionString="yourdatabase" name="LocalSqlServer" providerName="System.Data.SqlClient" />
</connectionStrings>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.