2015-03-03 63 views
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的增加引起的。所以我的错误在这里。

回答

0

找到原因。由于添加了引用属性(BarID),因此迁移被触发,因此这是一个不正确的问题。我的错。所以关闭它。