From the course: Using Entity Framework Core with Legacy Databases

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Adding concurrency tokens and timestamps

Adding concurrency tokens and timestamps

From the course: Using Entity Framework Core with Legacy Databases

Start my 1-month free trial

Adding concurrency tokens and timestamps

- Usually, applications against the database allow more than one user at a time. However, if two users modify a row at the same time, there's a problem, who's modification do we keep. We need to refresh the data and have the second user try again with more recent data, or find some other way to resolve the issue. Concurrency tokens allow entity framework to track specific columns for changes to ensure that a field within a row has not been modified since we last retrieved the data for it. In the order entity, we are using the last updated field, to serve this purpose. Let's start under the model folder with our data context. Scroll down to the order section, and find the last update property definition. The column has isRowVersion, which we mentioned before, which includes isConcurrencyToken. Since the last update is a rowVersion field, it will be updated when any row in this field is updated. If this field is different from when we first pulled the item, when we go to save the same…

Contents