Timestamp Attribute in Entity Framework

Using the Timestamp attribute in Entity Framework (EF) is one of the ways to handle the Concurrency issues. The Concurrency issue arises when multiple users attempt to update/delete the same row at the same time.  We can handle this issue either 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
  • 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. Required fields are marked *

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

Scroll to Top