In our project we have a DbContext for our code first database which is working fine. I've created a second DbContext (AppDbContext) to encapsulate login information. It will point to the same database, but will not need to see all the tables, or migrate.
When the Identity system initializes this context in my user manager:
var manager = new MkpUserManager(new UserStore<MkpUser, MkpRole, Guid, MkpLogin, MkpUserRole, MkpClaim>(context.Get<AppDbContext>()));
I get an error that:
Unable to determine the principal end of an association between the types 'PublicationSystem.Model.Organization' and 'PublicationSystem.Model.Resource'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.
Those two tables should not be handled by the AppDbContext. How can I get it to ignore them? Is having two DbContext files even practical?
Here's what AppDbContext looks like:
public class AppDbContext : IdentityDbContext<MkpUser, MkpRole, Guid, MkpLogin, MkpUserRole, MkpClaim>
{
#region Constructors
public AppDbContext()
: base("IdentityConnection")
{
}
#endregion
#region Methods
public static AppDbContext Create()
{
return new AppDbContext();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Map Entities to their tables.
modelBuilder.Entity<MkpUser>().ToTable("User");
modelBuilder.Entity<MkpRole>().ToTable("Role");
modelBuilder.Entity<MkpClaim>().ToTable("UserClaim");
modelBuilder.Entity<MkpLogin>().ToTable("UserLogin");
modelBuilder.Entity<MkpUserRole>().ToTable("UserRole");
// Set AutoIncrement-Properties
modelBuilder.Entity<MkpUser>().Property(r => r.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
modelBuilder.Entity<MkpClaim>().Property(r => r.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
modelBuilder.Entity<MkpRole>().Property(r => r.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
// Override some column mappings that do not match our default
modelBuilder.Entity<MkpUser>().Property(r => r.UserName).HasColumnName("Email");
modelBuilder.Entity<MkpUser>().Property(r => r.PasswordHash).HasColumnName("Password");
}
#endregion
}