简体   繁体   English

如何使用模型优先方法为乐观并发创建RowVersion列?

[英]How to create RowVersion column for optimistic concurrency using model first approach?

I am working on a legacy web app which implements model first(edmx file) approach using Entity Framework. 我正在使用旧版网络应用程序,该应用程序使用Entity Framework实现了模型优先(edmx文件)方法。

I need to implement optimistic concurrency, so I have added this field as following: 我需要实现乐观并发,因此我添加了以下字段:

在此处输入图片说明

and inside the database has been created as binary(8) type. 并且数据库内部已创建为binary(8)类型。 But when I try to update the entity is getting updated but the VersionRow values is not updated(no new value generated). 但是,当我尝试更新时,该实体正在更新,但VersionRow值未更新(未生成新值)。

PS PS

When I added the column I have binded default value as 0x0000000000000000 because it does not allow null values. 当我添加列时,我将默认值绑定为0x0000000000000000,因为它不允许空值。

Yea I solved it this way: 是的,我这样解决了:

1) I changed the type of RowVersion column from Binary(10) into timestamp inside SqlServer. 1)我将RowVersion列的类型从Binary(10)更改为SqlServer内部的时间戳。

2) In the property details inside the .edmx file I have put the property StoreGeneratedPattern of the property RowVersion as Computed . 2)在.edmx文件内的属性详细信息中,我将属性RowVersion的StoreGeneratedPattern属性设置为Computed

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

Now it became as following: 现在变成如下:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM