Background:
I have multiple classes called ApplicationDbContext. One is located in the root and the rest are divided up amongst their modularized area directories. Currently, I have the option of handling data migrations like so.
Question:
How would I rewrite each of my classes in the area folder's subdirectories to eliminate the individual migration calls?
Source:
Database Migration Commands Below
Establishing Migrations for Root Models
Enable-Migrations -ContextTypeName:JosephMCasey.Models.ApplicationDbContext -MigrationsDirectory:Migrations\Root
Add-Migration -configuration JosephMCasey.Migrations.Root.Configuration Root
Update-Database -configuration JosephMCasey.Migrations.Root.Configuration -Verbose
Establishing Migrations for each 'Areas' Model
Enable-Migrations -ContextTypeName:JosephMCasey.Areas.Article.Models.ApplicationDbContext -MigrationsDirectory:Migrations\Article
Add-Migration -configuration JosephMCasey.Migrations.Article.Configuration Article
Update-Database -configuration JosephMCasey.Migrations.Article.Configuration -Verbose
Idealized Migrations
Enable-Migrations
Add-Migration Application
Update-Database
C# Classes Below
Application\Models\IdentityModels.cs
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
Application\Areas\Article\Models\Article.cs
namespace JosephMCasey.Areas.Article.Models
{
public class ArticleContent
{
...
}
public class ApplicationDBContext : DbContext
{
public DbSet<ArticleContent> Articles { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<Tag> Tags { get; set; }
}
}
End Note
Am I just being too lazy or picky? Isn't it more effective to run a single context? I am new to this, so my understanding of best practices are shaky at best.
Resources for Guidance
Code First Migration in Multiple DbContext
Inheritance in Entity Framework: Table per Hierarchy
Package Manager Console Commands - get-help Enable-Migrations -detailed & get-help Add-Migration -detailed & get-help Update-Database -detailed