The TimeStamp Attribute

The TimeStamp attribute is used to specify that a property should take part in concurrency management.

The TimeStamp attribute is only valid if applied to a property that is a byte array. How this is implemented is dependent on the current database provider. In SQL Server, this will map to a rowversion type.

public class Author
{
    public int AuthorId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public ICollection<Book> Books { get; set; }
    [TimeStamp]
    public byte[] RowVersion { get; set; }
}

Fluent API

The Fluent API equivalent to the TimeStamp attribute is the IsConcurrencyToken method chained with the ValueGeneratedOnAddOrUpdate method.

From version 1.1 of EF Core, The IsRowVersion method will also be available which acts as a convenience wrapper for the chained combination described above.

Further Reading


Created:
Last updated: 14/03/2017 16:33:43
Proficiency Level: Beginner