daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest Aug 16th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. namespace MyProject
  2. {
  3.     public class ApplicationDbContext : IdentityDbContext
  4.     {
  5.         public ApplicationDbContext() : base("ApplicationDbContext")
  6.         {
  7.         }
  8.  
  9.         public virtual DbSet<Person> People { get; set; }
  10.     }
  11.  
  12.     public class Person
  13.     {
  14.         public string Age { get; set; }
  15.         public int Id { get; set; }
  16.         public string Name { get; set; }
  17.         public string SomePropertyA { get; set; }
  18.         public string Surname { get; set; }
  19.     }
  20.  
  21. //Global.asax.cs
  22.     public class MvcApplication : HttpApplication
  23.     {
  24.         protected void Application_Start()
  25.         {
  26.             Database.SetInitializer(new CreateDatabaseIfNotExists<ApplicationDbContext>());
  27.  
  28.             DbMigrator dbMigrator;
  29.  
  30.             //NOTE: not the actual code, but this is what is comes down to
  31.             if (AreaA.IsActive)
  32.                 dbMigrator = new DbMigrator(new Area_A_Configuration());
  33.             else if(AreaB.IsActive)
  34.                 dbMigrator = new DbMigrator(new Area_B_Configuration());
  35.             else
  36.                 dbMigrator = new DbMigrator(new Configuration());
  37.  
  38.             dbMigrator.Update();
  39.         }
  40.     }
  41. }
  42.  
  43. namespace MyProject.Areas.Area_A
  44. {
  45.     public class Area_A_DbContext : ApplicationDbContext
  46.     {
  47.         public virtual DbSet<Area_A_Person> A_People { get; set; }
  48.     }
  49.  
  50.     public class Area_A_Person : Person
  51.     {
  52.         public string SomeProperty_A { get; set; }
  53.     }
  54.  
  55.     internal sealed class Area_A_Configuration : DbMigrationsConfiguration<Area_A_DbContext>
  56.     {
  57.         public Configuration() : base()
  58.         {
  59.             AutomaticMigrationsEnabled = true;
  60.             AutomaticMigrationDataLossAllowed = true;
  61.         }
  62.     }
  63. }
  64.  
  65. namespace MyProject.Areas.Area_B
  66. {
  67.     public class Area_B_DbContext : ApplicationDbContext
  68.     {
  69.         public virtual DbSet<Area_B_Person> B_People { get; set; }
  70.     }
  71.  
  72.     public class Area_B_Person : Person
  73.     {
  74.         public string SomeProperty_B { get; set; }
  75.     }
  76.  
  77.     internal sealed class Area_B_Configuration : DbMigrationsConfiguration<Area_B_DbContext>
  78.     {
  79.         public Configuration() : base()
  80.         {
  81.             AutomaticMigrationsEnabled = true;
  82.             AutomaticMigrationDataLossAllowed = true;
  83.         }
  84.     }
  85. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top