【发布时间】:2015-07-15 01:52:05
【问题描述】:
我正在使用具有多个现有数据库的实体框架。
- 1x 父
- 3x 孩子
我的目标是拥有两个数据库上下文,一个支持父级,一个支持子级。我还打算在两个上下文中设置并启用自动迁移。
我的子上下文传入连接字符串名称以确定要创建哪个子连接
/// <summary>
/// Represents a child database context within a hierarchy
/// </summary>
public class ChildDbContext : DbContext
{
public ChildDbContext(string name) : base(name)
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<ChildDbContext, Migrations.Configuration>());
}
}
问题
自动迁移是否会在第一次访问时更新每个子数据库,即我第一次访问new ChildDbContext("Child1")、new ChildDbContext("Child2")、new ChildDbContext("Child3")?
我不能 100% 确定何时实际执行迁移检查,或者它是否可以在没有无参数构造函数的情况下工作。
【问题讨论】:
标签: entity-framework entity-framework-migrations