Search code examples
c#sql-serverentity-frameworkconcurrency

Entity Framework IsRowVersion() without concurrency check


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();

Solution

  • 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);