I'm using EntityFramework 6. I would like to split my DbContext into multiple smaller ones. Edit: I have a single database I wish to connect to.
I will have a single DbContext with all the entities and migrations that only one central application will use. Other applications will use the smaller DbContext without migrations.
I have found that I need to inherit all DbContext from IdentityDbContext, even if they use none of it.
internal class SmallerDbContext : IdentityDbContext<ApplicationUser,
ApplicationRole, int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
public DbContext<Entity1> NotInSmallerDbContext { get; set; }
public DbContext<Entity1> InSmallerDbContext { get; set; }
}
I would like this to be:
internal class SmallerDbContext : System.Data.Entity.DbContext
{
public DbContext<Entity1> InSmallerDbContext { get; set; }
}
But this yields the following errors:
Paris.DAL.Repo.DbContext.ApplicationUserLogin: : EntityType 'ApplicationUserLogin' has no key defined. Define the key for this EntityType.
Paris.DAL.Repo.DbContext.ApplicationUserRole: : EntityType 'ApplicationUserRole' has no key defined. Define the key for this EntityType.
ApplicationUserLogins: EntityType: EntitySet 'ApplicationUserLogins' is based on type 'ApplicationUserLogin' that has no keys defined.
ApplicationUserRoles: EntityType: EntitySet 'ApplicationUserRoles' is based on type 'ApplicationUserRole' that has no keys defined.
I have tried to add these tables to the DbContext, but to no avail.
public IDbSet<ApplicationUser> Users { get; set; }
public IDbSet<ApplicationRole> Roles { get; set; }
Is there any way I can create DbContext that does not inherit from IdentityDbContext?