Entity Framework Core Interview Question #118
What is a concurrency token in EF Core?
Change Tracking, Updates, Transactions & Concurrency Mid-Level Intermediate
Quick Interview Answer
A concurrency token is a property whose original value participates in the condition used for UPDATE or DELETE operations. It helps EF Core detect whether the database row changed since the entity was originally read.
Detailed Explanation
A concurrency token is a property whose original value participates in the condition used for UPDATE or DELETE operations. It helps EF Core detect whether the database row changed since the entity was originally read.
A token can be database-generated, such as a SQL Server rowversion, or application-managed depending on the design and provider.
Concurrency tokens should cover the conflict semantics required by the business process.
Code Example
public class Product
{
public int Id { get; set; }
[Timestamp]
public byte[] RowVersion { get; set; } = Array.Empty<byte>();
}