2

I have an MVC5 application using Entity Framework 6.1 and Asp.Net Identity 2 and have data migrations enabled. I have used sample code from other answers on StackExchange to seed the Role and User tables. My application data context is based on IdentityDbContext. On issuing an update-database command, my database is created and populated with the following tables:

List of tables from SQL Server Object Explorer

My app launches OK, but when I try to log in using the seeded user (or any user for that matter), I get the following error: Screen shot of error message

How can I get SignInManager to reference the IdentityUsers table instead of AspNetUsers?

Tony Bater
  • 327
  • 6
  • 17

1 Answers1

3

You can set custom names in OnModelCreating

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

    mb.Entity<User>().ToTable("IdentityUsers");
   ...
}
fly_ua
  • 1,034
  • 8
  • 12
  • Where is the definition of ? I have also tried Entity, as in the missing object, but both show an error that "The type or namespace name 'User/AspNetUser' cannot be found (are you missing a using directive or assembly reference?)' – Tony Bater Dec 08 '14 at 14:19
  • User should be entity name generated from Identity 2.0 CodeFirst – fly_ua Dec 08 '14 at 14:40
  • I now have the project building OK with the line `modelBuilder.Entity().ToTable("IdentityUsers");` but when I run update-database in PackageManagerConsole I get this error: `One or more validation errors were detected during model generation: IdentityUser_Logins_Target: : Multiplicity is not valid in Role 'IdentityUser_Logins_Target' in relationship 'IdentityUser_Logins'. Because the Dependent Role refers to the key properties, the upper bound of the multiplicity of the Dependent Role must be '1'` – Tony Bater Dec 08 '14 at 15:12