Code First Migration忽略DatabaseGeneratedOption?

时间:2014-08-15 14:17:48

标签: entity-framework ef-code-first ef-migrations

我尝试将字段更改为计算字段。

即来自:

        Property(c=>c.IsPaid)
            .IsRequired();

成:

        Property(c=>c.IsPaid)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed)
            .IsRequired();

然后添加迁移后:

Add-Migration IsPaidAsComputed

脚手架迁移给了我一个迁移类:

public partial class IsPaidAsComputed : DbMigration
{
    public override void Up()
    {
        AlterColumn("dbo.Citations", "IsPaid", c => c.Boolean(nullable: false));
    }

    public override void Down()
    {
        AlterColumn("dbo.Citations", "IsPaid", c => c.Boolean(nullable: false));
    }
}

实体框架是不是很聪明,无法发现我们的意图变化是什么?

AlterColumn进入计算字段的正确方法是什么?

0 个答案:

没有答案