我在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尝试将此列设置为时间戳,也许我自己删除并重新创建表?

最佳答案


        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/

10-10 17:29