Entity Framework IsRowVersion() without concurrency check

不羁岁月 提交于 2020-01-25 21:03:35

问题


We have a table that has a column called Version that is mapped as a SQL rowversion. This is done because we have an external system that maps to our data that relies on this column changing every time the table is updated. Originally we wanted this to be handled by SQL, but now we are finding we have Optimistic Concurrency exceptions. While these exceptions are there to safeguard data getting overwritten, for our case we do not care about this. We simply want the timestamp to continue incrementing, without Entity Framework checking it for concurrency issues.

Is there any way to do this?

Mapping:

Property(t => t.Version).IsRowVersion();

回答1:


By default EF implies row version type to be a optimistic concurrency token (included in the optimistic concurrency checks).

You can override that behavior by using the IsConcurrencyToken fluent API:

Property(t => t.Version).IsRowVersion().IsConcurrencyToken(false);


来源:https://stackoverflow.com/questions/44313258/entityframework-core-update-record-fails-with-dbupdateconcurrencyexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!