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
1 2 3 4 5 6 7 8 9 10 | public class Employee { public int EmployeeID { get; set; } public string Name { get; set; } public string Address { get; set; } [Timestamp] public byte[] RowID { get; set; } } |
- We can apply
Timestamp
attribute to only one property in the domain model. - The data type of the
Timestamp
must be abyte
array - This attribute affects the database as it creates the column with datatype
rowversion
.byte[]
array withoutTimestamp
creates thevarninary(max)
column Timestamp
columns are the preferred way of using for concurrency check