Entity Framework Core Interview Question #119

What is rowversion and how is it used with EF Core on SQL Server?

Change Tracking, Updates, Transactions & Concurrency Mid-Level Intermediate

Quick Interview Answer

SQL Server rowversion is a database-generated binary value that changes when a row is updated. EF Core can map it as a concurrency token.

Detailed Explanation

SQL Server rowversion is a database-generated binary value that changes when a row is updated. EF Core can map it as a concurrency token.

When an entity is updated, EF Core can include the original rowversion in the WHERE clause. If the rowversion no longer matches, the update affects no row and a concurrency exception is raised.

A rowversion is not a date or time value despite older terminology that may call the type timestamp.

Code Example

modelBuilder.Entity<Product>()
    .Property(p => p.RowVersion)
    .IsRowVersion();