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
You may get the following message if you follow the above steps but can't work out how to provide the key information. The error you may receive is:
IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType. Context.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType.
Create the two following classes
public class IdentityUserLoginConfiguration : EntityTypeConfiguration
{
public IdentityUserLoginConfiguration()
{
HasKey(iul => iul.UserId);
}
}
public class IdentityUserRoleConfiguration : EntityTypeConfiguration
{
public IdentityUserRoleConfiguration()
{
HasKey(iur => iur.RoleId);
}
}
In the OnModelCreating method within your Applications DbContext add the two configurations outlined above to the model:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new IdentityUserLoginConfiguration());
modelBuilder.Configurations.Add(new IdentityUserRoleConfiguration());
}
This should now get rid of the error methods when your model is being created. It did for me.