Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace MyProject
- {
- public class ApplicationDbContext : IdentityDbContext
- {
- public ApplicationDbContext() : base("ApplicationDbContext")
- {
- }
- public virtual DbSet<Person> People { get; set; }
- }
- public class Person
- {
- public string Age { get; set; }
- public int Id { get; set; }
- public string Name { get; set; }
- public string SomePropertyA { get; set; }
- public string Surname { get; set; }
- }
- //Global.asax.cs
- public class MvcApplication : HttpApplication
- {
- protected void Application_Start()
- {
- Database.SetInitializer(new CreateDatabaseIfNotExists<ApplicationDbContext>());
- DbMigrator dbMigrator;
- //NOTE: not the actual code, but this is what is comes down to
- if (AreaA.IsActive)
- dbMigrator = new DbMigrator(new Area_A_Configuration());
- else if(AreaB.IsActive)
- dbMigrator = new DbMigrator(new Area_B_Configuration());
- else
- dbMigrator = new DbMigrator(new Configuration());
- dbMigrator.Update();
- }
- }
- }
- namespace MyProject.Areas.Area_A
- {
- public class Area_A_DbContext : ApplicationDbContext
- {
- public virtual DbSet<Area_A_Person> A_People { get; set; }
- }
- public class Area_A_Person : Person
- {
- public string SomeProperty_A { get; set; }
- }
- internal sealed class Area_A_Configuration : DbMigrationsConfiguration<Area_A_DbContext>
- {
- public Configuration() : base()
- {
- AutomaticMigrationsEnabled = true;
- AutomaticMigrationDataLossAllowed = true;
- }
- }
- }
- namespace MyProject.Areas.Area_B
- {
- public class Area_B_DbContext : ApplicationDbContext
- {
- public virtual DbSet<Area_B_Person> B_People { get; set; }
- }
- public class Area_B_Person : Person
- {
- public string SomeProperty_B { get; set; }
- }
- internal sealed class Area_B_Configuration : DbMigrationsConfiguration<Area_B_DbContext>
- {
- public Configuration() : base()
- {
- AutomaticMigrationsEnabled = true;
- AutomaticMigrationDataLossAllowed = true;
- }
- }
- }
Add Comment
Please, Sign In to add comment