我在 EF6 中有一个对象,我忘记从我的 auditableEntity 类继承。这个类有这样的配置
public abstract class AuditableEntityConfig<TEntity> : BaseEntityConfig<TEntity> where TEntity : AuditableEntity
{
public AuditableEntityConfig()
: base()
{
this.Property(e => e.RowVersion)
.IsRowVersion();
}
}
现在我已经更新了我的实体以继承自此类,现在在运行我的代码时,我总是会收到一条错误消息
Cannot alter column 'RowVersion' to be data type timestamp.
我是否可以阻止 EF 尝试将此列设置为时间戳,也许我自己删除并重新创建表?
最佳答案
Replace one line
AlterColumn
with 2 linesDropColumn
andAddColumn
in Up() method.
public override void Up()
{
DropColumn("dbo.Cities", "RowVersion", null);
AddColumn("dbo.Cities", "RowVersion", c => c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"));
}
public override void Down()
{
AlterColumn("dbo.Cities", "RowVersion", c => c.Binary());
}
关于c# - EF 迁移和时间戳列,无法更新/运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28736194/