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
的增加引起的。所以我的錯誤在這裏。