为什么EF6会创建这种疯狂的迁移?

时间:2016-08-09 23:30:55

标签: c# entity-framework entity-framework-6 ef-migrations

我使用的是EF 6.1.3。

这是我最初的架构:

[Table("Children")]
public class Child
{
    [Key]
    public int Id { get; set; }

    public virtual Parent Parent { get; set; }
}

[Table("Parents")]
public class Parent
{
    [Key]
    public int Id { get; set; }

    [InverseProperty("Parent")]
    public virtual ICollection<Child> Children { get; set; }
}

当我将关联的多样性更改为(我使用edmx执行此IRL时,但此示例说明了问题):

[Table("Children")]
public class Child
{
    [Key]
    public int Id { get; set; }

    [Required]
    public virtual Parent Parent { get; set; }
}


[Table("Parents")]
public class Parent
{
    [Key]
    public int Id { get; set; }

    public virtual Child Child { get; set; }
}

据我所知,唯一必要的数据库架构更改是Children.Parent列的可为空性。然而,EF产生了这种疯狂:

    public override void Up()
    {
        DropIndex("dbo.Children", new[] { "Parent_Id" });
        DropColumn("dbo.Children", "Id");
        RenameColumn(table: "dbo.Children", name: "Parent_Id", newName: "Id");
        DropPrimaryKey("dbo.Children");
        AlterColumn("dbo.Children", "Id", c => c.Int(nullable: false));
        AlterColumn("dbo.Children", "Id", c => c.Int(nullable: false));
        AddPrimaryKey("dbo.Children", "Id");
        CreateIndex("dbo.Children", "Id");
    }

这显然毫无意义。

WTF正在这里?

0 个答案:

没有答案