c# - EF 迁移和时间戳列,无法更新/运行

标签 c# .net entity-framework entity-framework-6

我在 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 lines DropColumn and AddColumn 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/

相关文章:

c# - 在 EF 6 中自动生成时间戳(代码优先): conversion of a datetime2 data type to a datetime data is an out-of-range value

c# - 放置 Database.SetInitializer 的地方

c# - DockPanelSuite 的 DockState 和 AutoHide

c# - 如何将 wpf treeview 与不同类型的嵌套对象一起使用

javascript - 如何使用 Javascript 呈现页面详细信息

c# - 完全无法定义System.Runtime.Caching的UpdateCallback

c# - 处理 : both fields equal or both null or empty 的 linq 函数

c# - 为什么 C# 结构不能返回对其成员字段的引用?

c# - 使用动态加载的 .Net 程序集进行二进制序列化

c# - ElasticSearch-过滤类型