0
我有实体,比如这个:为什么新建一个属性为虚拟的迁移?
public class Foo
{
public int Id { get; set; }
public Bar Bar { get; set; }
public Bar2 Bar2 { get; set; }
}
public class Bar
{
public int Id { get; set; }
public string Description { get; set; }
}
public class Bar2
{
public int Id { get; set; }
public string Description { get; set; }
}
哪些迁移是:
CreateTable(
"dbo.Bar",
c => new
{
Id = c.Int(nullable: false, identity: true),
Description = c.String(),
})
.PrimaryKey(t => t.Id);
CreateTable(
"dbo.Bar2",
c => new
{
Id = c.Int(nullable: false, identity: true),
Description = c.String(),
})
.PrimaryKey(t => t.Id);
CreateTable(
"dbo.Foo",
c => new
{
Id = c.Int(nullable: false, identity: true),
Bar_Id = c.Int(),
Bar2_Id = c.Int(),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.Bar", t => t.Bar_Id)
.ForeignKey("dbo.Bar2", t => t.Bar_Id)
.Index(t => t.AlertCause_Id)
然后我设置为美孚一间酒吧财产virtual
,并将其与“AutomaticMigrationsDisabledException打破:无法更新数据库匹配当前模型,因为有未决的更改并且自动迁移已禁用。“在迁移重建脚手架之后,代码更改仅在Bar_Id
变为BarId
,但对于Bar2
它仍然为Bar2_Id
。所以我想知道为什么如果它看起来没有改变任何东西,那么为什么它会让我迁移到重建的脚手架?是的,它需要代理类和延迟加载等,但为什么新的迁移?谢谢!
UPDATE
我已经错过了迁移实际上是由一个外键属性,BarId
的增加引起的。所以我的错误在这里。