Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like you didn't have specified the <code>stamp</code> property as a rowversion in your model and it is just a binary field. You can specify it with Fluent API:</p> <pre><code>modelBuilder.Entity&lt;Driver&gt;().Property(d =&gt; d.stamp) .IsRowVersion() .IsConcurrencyToken(false); </code></pre> <p>The code above is for the case when you don't want to have the <code>stamp</code> property as a concurrency token. (A rowversion is a concurrency token by default, so you have to disable it explicitly.) If you want to have it as concurrency token, then you can use with Fluent API...</p> <pre><code>modelBuilder.Entity&lt;Driver&gt;().Property(d =&gt; d.stamp) .IsRowVersion(); </code></pre> <p>...or with data annotations:</p> <pre><code>[Timestamp] public byte[] stamp { get; set; } </code></pre> <p>This should prevent EF to write an UPDATE for this property.</p> <p><strong>Edit</strong></p> <p>If you use Database-First strategy the <code>[Timestamp]</code> attribute does not work. This attribute is only for Code-First development.</p> <p>When you use Database-First the connection string contains a metadata section refering to the EDM defined in the EDMX file:</p> <pre><code>connectionString="metadata=res://*/Model1.csdl |res://*/Model1.ssdl |res://*/Model1.msl; ... ..." </code></pre> <p>If Entity Framework finds this section in the connection string it doesn't use data annotations on model properties nor does it process any code in Fluent API (<code>OnModelCreating</code> isn't called at all). Instead it loads the mapping definitions from the embedded and compiled EDMX file.</p> <p>That means, if you want to define the <code>stamp</code> property as a concurrency token you <em>must</em> do this in the EDMX file. In XML it would look like this:</p> <p>In SSDL section:</p> <pre class="lang-xml prettyprint-override"><code>&lt;Property Name="stamp" Type="timestamp" Nullable="false" StoreGeneratedPattern="Computed" /&gt; </code></pre> <p>In CSDL section:</p> <pre class="lang-xml prettyprint-override"><code>&lt;Property Name="stamp" Type="Binary" Nullable="false" MaxLength="8" FixedLength="true" annotation:StoreGeneratedPattern="Computed" ConcurrencyMode="Fixed" /&gt; </code></pre> <p>You can also define this in the model designer in Visual Studio: Mark the <code>stamp</code> property in the entity in the designer surface, go to the Properties Window and set "Concurrency Mode" to "Fixed" (and also set the "StoreGeneratedPattern" to "Computed").</p> <p>You can also remove the metadata section from the connection string. But this effectively means that you switch from database first to code first development. Then all attributes and Fluent API will be respected, but not any definitions in EDMX anymore.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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