I have a class library project named "Core" which defines CoreContext with properties for common classes:
public class CoreContext : DbContext
{
public DbSet<User> Users { get; set; }
public DbSet<Role> Roles { get; set; }
public DbSet<UserContactInfo> UserContactInfos { get; set; }
... more common properties ...
}
Then I have multiple projects referencing the "Core" project and defining new Contexts inheriting CoreContext:
Project1:
public class Project1Context : CoreContext
{
public DbSet<Foo> Foos { get; set; } //object defined in Project1
}
Project2:
public class Project2Context : CoreContext
{
public DbSet<Bar> Bars { get; set; } //object defined in Project2
}
When I change something in Project1Context I create a new migration in Project1 which is OK,
but if I change something in the Core project, lets say add property Company
to UserContactInfo
I will have to go to Project1 and Project2 and add new migration and I will end up with migrations related to the Core project in Project1 and Project2.
My question is: Is there a way I can keep the migrations for CoreContext in the Core project and Project1Context and Project2Context migrations to their corresponding project and automatically execute all migrations related to the project, so when I start Project1 it will run its own migrations and CoreContext migrations?
As clarification, I have separate databases for Project1 and Project2 and recently Updated EF to version 6.