The IsRowVersion
method is used to denote that a property should take part in concurrency management.
When applied to a byte array property, the IsRowVersion
method denotes that the property should map to a database type that provides automatic row-versioning, such as the SQL Server rowversion
type:
language-csharp
|
public class SampleContext : DbContext
{
public DbSet<Author> Authors { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Author>()
.Property(a => a.RowVersion)
.IsRowVersion();
}
}
public class Author
{
public int AuthorId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Biography { get; set; }
public ICollection<Book> Books { get; set; }
public byte[] RowVersion { get; set; }
}
The IsRowVersion
method was introduced in EF Core 1.1 as a wrapper around the IsConcurrencyToken method chained with the ValueGeneratedOnAddOrUpdate method.
Data Annotations
The Data Annotations equivalent to the IsRowVersion
method is the Timestamp attribute.