Timestamp Attribute in EF Core

Using Timestamp Attribute in Entity Framework Core is a way to handle the Concurrency issues. The Concurrency issue arises when multiple users attempt to update/delete the same row at the same time.  This issue can be handled either by using the Timestamp column or ConcurrencyCheck attribute on the property. Timestamp columns are the preferred way of using for concurrency check.

You can apply Timestamp attribute to any byte array column as shown in the entity model below. The Attribute is applied to RowID Property. The entity framework automatically adds the TimeStamp columns in update/delete queries.  This attribute resides in the namespace system.componentmodel.dataannotations.schema

Timestamp Attribute in Entity Framework
Timestamp Attribute in Entity Framework Core

Best Entity Framework Core Books
The Best EF Core Books, which helps you to get started with EF Core  

  • We can apply Timestamp attribute to only one property in the domain model.
  • The data type of the Timestamp must be a byte array
  • This attribute affects the database as it creates the column with datatype rowversion. byte[]  array without Timestamp creates the varninary(max) column
  • Timestamp columns are the preferred way of using for concurrency check

References

  1. TimestampAttribute 

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top