I have an ASP.NET MVC App, which use EF code First, for some reason I need to use 2 differents DBContext for my app like the example here:
namespace ESN.Models { public class CoreA { //.......... } public class CoreB { //.......... } public class CoreDbContext : DbContext { public DbSet<CoreA> CoreA { get; set; } public DbSet<CoreB> CoreB { get; set; } } public class StuffA { //.......... } public class StuffB { //.......... } public class StuffDbContext : DbContext { public DbSet<StuffA> StuffA { get; set; } public DbSet<StuffB> StuffB { get; set; } } } And for the convenient developing I add some code that drop and re-create the database if model has change:
Database.SetInitializer<CoreDbContext>(new DropCreateDatabaseIfModelChanges<CoreDbContext>()); Database.SetInitializer<StuffDbContext>(new DropCreateDatabaseIfModelChanges<StuffDbContext>()); But the issue is they just Create new table for the DbContent that I need to use first, the Core table exist but none of the Stuff!
Thanks for your help!