Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What fluent api method is correspond to [Timestamp] attribute in Data Annotations API to check concurrency

I am using Entity Framework 4.1. What fluent api method is correspond to [Timestamp] attribute in Data Annotations API to check concurrency?

like image 910
Ray Avatar asked May 29 '11 10:05

Ray


1 Answers

If you have class like this:

public class MyEntity
{
    ...
    public byte[] Timestamp { get; set; }
}

You will use fluent mapping like this:

modelBuilder.Entity<MyEntity>()
            .Property(e => e.Timestamp)
            .IsConcurrencyToken()
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);

Or:

modelBuilder.Entity<MyEntity>()
            .Property(e => e.Timestamp)
            .IsRowVersion();              
like image 57
Ladislav Mrnka Avatar answered Oct 18 '22 06:10

Ladislav Mrnka