EF Code First - IsConcurrencyToken ()

Simple but still cryptic to me: why do StringPropertyConfiguration (and all other PropertyConfiguration properties) have 2 overloads for IsConcurrencyToken() ?

First:

public StringPropertyConfiguration IsConcurrencyToken()

Configures a property that will be used as an optimistic concurrency token.

And the second:

public StringPropertyConfiguration IsConcurrencyToken(bool?)

Determines whether a property should be used as an optimistic concurrency.

Why are you using one over the other? As I can see, there is no difference between these two overloads (at least not when working with them) ...

Using the first, you should write something like:

 modelBuilder.Entity<Author>() .Property(x => x.Name) .IsConcurrencyToken(); 

And using the second, you should write:

 modelBuilder.Entity<Author>() .Property(x => x.Name) .IsConcurrencyToken(true/false/null); 

Did I miss something?

+4
source share
1 answer

My opinion...

The IsConcurrencyToken() value of IsConcurrencyToken() is true to provide an easy, free way to define an object.

IsConcurrencyToken(bool?) Allows the author to finally set the ConcurrencyMode object. This is useful for advanced scripts:

  • Overriding the [ConcurrencyCheck] attribute on POCO
  • Agreement permission (removed in EF 4.1 RTW) to enable / disable ConcurrencyMode based on user agreement

Finally, I think IsConcurrencyToken(false) better than IsNotConcurrencyToken() .

+4
source

All Articles