I'm using a custom implementation of the IdentityUser class in my project.
The problem is that Entity Framework adds an extra column in the table IdentityUserRoles, mapping the child class Id as a constraint.
I know that EF is probably getting confused on figuring how to map the relationship with this new class, I just don't know why and how to solve it. I've been searching the web about this EF behavior, but couldn't find a solution yet.
Here are some screenshots that summarize the problem:
I've found the same issue. There is a much simpler solution. You should explicitly define the relation on the IdentityUserRole configuration.
E.g.:
Cannot supply a full technical explanation but I made these changes in my code to overcome the problem:
: :
So, generally commented out everything and changed from IdentityUser to ApplicationUser. But need to add that I originally had code for Identity 1.0 Hope it can help you!
So, I've rechecked my database mappings, and I think I have found a solution for this problem:
My user class mapping was located in another file (UsuarioMap), that inherited from EntityTypeConfiguration, and then I would specify my configurations in its constructor, exactly like the image in the post. (IMHO this is better for code organization). Now my IdentityUser (Usuario) table configuration it's simply located inside the OnModelCreating method:
I honestly don't know why Entity Framework look at this two configurations paths differently since the parameter of modelBuilder.Configurations.Add() and the return of modelBuilder.Entity() is a System.Data.Entity.ModelConfiguration.EntityTypeConfiguration object, so logically both ways should work.