Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Like it mentioned, the best practice is to use a column of row version type in your DB table for concurrency checking, but how it is implemented with Code First: <br> When using Code First in CTP3, you would need to use the fluent API to describe which properties needs concurrency checking but in CTP4 this can be done declaratively as part of the class definition using data annotation attributes: </p> <h3>ConcurrencyCheckAttribute:</h3> <p><a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.concurrencycheckattribute.aspx" rel="nofollow"><em>ConcurrencyCheckAttribute</em></a> is used to specify that a property has a concurrency mode of “fixed” in the model. A fixed concurrency mode means that this property is part of the concurrency check of the entity during save operations and applies to <em>scalar</em> properties only:</p> <pre><code>public class Sale { public int SaleId { get; set; } [ConcurrencyCheck] public string SalesPersonName { get; set; } } </code></pre> <p>Here, ConcurrencyCheck will be turn on for <code>SalesPersonName</code> property. However, if you decide to include a dedicated Timestamp property of type byte[] in your class then TimestampAttribute will definitely be a better choice to go for:</p> <h3>TimestampAttribute:</h3> <p><a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.timestampattribute.aspx" rel="nofollow"><em>TimestampAttribute</em></a> is used to specify that a <em>byte[] property</em> has a concurrency mode of “fixed” in the model and that it should be treated as a <em>timestamp column</em> on the store model (non-nullable byte[] in the CLR type). This attribute applies to scalar properties of type <em>byte[] only</em> and only one TimestampAttribute can be present on an entity.</p> <pre><code>public class Sale { public int SaleId { get; set; } [Timestamp] public byte[] Timestamp { get; set; } } </code></pre> <p>Here, not only <code>Timestamp</code> property will be taken as concurrency token, but also EF Code First learn that this property has store type of <em>timestamp</em> and also that this is a <em>computed column</em> and we will not be inserting values into this property but rather, the value will be computed on the SQL Server itself.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload