I am looking at some code online where there are two Contexts for the same database (one for read and one for write):
public class OrderReadContext: DbContext
{
public OrderReadContext() : base("name=GeekStuffSales") {
}
public DbSet<SalesOrder> Orders { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder) {
modelBuilder.HasDefaultSchema("Order");
}
}
public class OrderSystemContextConfig : DbConfiguration
{
public OrderSystemContextConfig() {
SetDatabaseInitializer(new NullDatabaseInitializer<OrderReadContext>());
}
}
Ladislav Mrnkas' answer to this post explains that the initializer must be set to null in sub contexts: Entity Framework: One Database, Multiple DbContexts. Is this a bad idea?
Why must the Database Initializer be set to null in a sub context?
I tried adding a seed method to one of my sub contexts, however this causes an error saying there are outstanding migrations. Is this not allowed?