【问题标题】:How to create RowVersion column for optimistic concurrency using model first approach?如何使用模型优先方法为乐观并发创建 RowVersion 列?
【发布时间】:2017-09-27 13:04:07
【问题描述】:

我正在开发一个使用实体框架实现模型优先(edmx 文件)方法的旧版网络应用程序。

我需要实现乐观并发,所以我添加了这个字段如下:

并且在数据库内部已经创建为 binary(8) 类型。 但是当我尝试更新实体时,实体正在更新,但 VersionRow 值未更新(未生成新值)。

附言

当我添加列时,我将默认值绑定为 0x0000000000000000,因为它不允许空值。

【问题讨论】:

    标签: entity-framework edmx ef-model-first optimistic-concurrency


    【解决方案1】:

    是的,我是这样解决的:

    1) 我将 RowVersion 列的类型从 Binary(10) 更改为 SqlServer 中的时间戳。

    2) 在 .edmx 文件内的属性详细信息中,我将属性 RowVersion 的属性 StoreGeneratedPattern 设置为 Computed

    Computed it means that a new value is generated on insert and update.
    

    现在变成了这样:

    【讨论】:

      猜你喜欢
      • 2015-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多