我尝试将字段更改为计算字段。
即来自:
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
进入计算字段的正确方法是什么?