-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 ?

eXPerience
  • 346
  • 1
  • 3
  • 19

1 Answers1

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>
Community
  • 1
  • 1
patrykgliwinski
  • 316
  • 1
  • 8