I have a MyDbContext in a separated Data Accass Layer class library project. And I have an ASP.NET MVC 5 project with a default IdentityDbContext. The two context use the sa
This may be an old thread, but this article was very helpful in demonstrating how to get the solution to the above question working: http://blogs.msdn.com/b/webdev/archive/2014/03/20/test-announcing-rtm-of-asp-net-identity-2-0-0.aspx
I did end having to include
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
//....
}
because without it, I would get the following error:
EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType. EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType. EntitySet 'IdentityUserRoles' is based on type 'IdentityUserRole' that has no keys defined. EntitySet 'IdentityUserLogins' is based on type 'IdentityUserLogin' that has no keys defined.
If I add these configurations as mentioned above:
public class IdentityUserLoginConfiguration : EntityTypeConfiguration
{
public IdentityUserLoginConfiguration()
{
HasKey(iul => iul.UserId);
}
}
public class IdentityUserRoleConfiguration : EntityTypeConfiguration
{
public IdentityUserRoleConfiguration()
{
HasKey(iur => iur.RoleId);
}
}
it would create an additional foreign key called Application_User.