我有一个项目,我的域在一堆单独的程序集和DbContexts之间进行了拆分,所有程序都使用相同的底层Sql Server数据库。这些程序集不会互相引用 - 有一个程序包含可能调用共享实体的内容,这些内容对所有其他域都是共同的,有时也称为导航属性。简单的例子:在添加迁移过程中忽略引用程序集中的实体
// Shared.dll
namespace Shared
{
// Shared POCO
class Hero
{
public string Name { get; set; }
public string Description { get; set; }
}
class MyDbContext : DbContext
{
public virtual DbSet<Hero> Heroes { get; set; }
}
internal sealed class MyDbContextConfiguration : DbMigrationsConfiguration<MyDbContext>
{
public MyDbContextConfiguration()
{
AutomaticMigrationsEnabled = false;
MigrationsDirectory = @"Migrations\MyDbContext";
ContextKey = "Shared";
}
}
}
// Game.dll <- references Shared.dll
namespace Game
{
// Individual POCO
class Mission
{
public string Name { get; set; }
public virtual ICollection<Hero> Protagonists { get; set; }
}
class MyDbContext : DbContext
{
public virtual DbSet<Mission> Missions { get; set; }
}
internal sealed class MyDbContextConfiguration : DbMigrationsConfiguration<MyDbContext>
{
public MyDbContextConfiguration()
{
AutomaticMigrationsEnabled = false;
MigrationsDirectory = @"Migrations\MyDbContext";
ContextKey = "Game";
}
}
}
的问题是,当我有Hero
POCO通过ICollection<Hero> Protagonists
导航属性Game.dll装配模型引用,称:
add-migration Test -ProjectName:Game -ConfigurationTypeName MyDbContextConfiguration -StartUpProjectName Main
创造DbMigration结束了这包括Hero
实体与引用的Shared.dll asssembly的更改。
public partial class Test : DbMigration
{
public override void Up()
{
AddColumn("shared.Heroes", "Name", c => c.String());
AddColumn("shared.Heroes", "Description", c => c.String());
...
如何限制add-migration
只为位于大会实体的变化进行监测,其中的DbContext已被定义?换句话说,当运行add-migration
针对Games.dll我想忽略对实体的任何更改Shared.dll。
什么也可以工作将是限制命名空间或数据库对象模式的能力。我只是不希望对位于引用程序集中的实体进行任何更改以包含在我的迁移中,因为所有迁移均按每个程序集进行维护。