title: DbUpdateConcurrencyException using Entity Framework 6 with MySql
body: <p>I'm having trouble with concurrency checks using EF6 and MySQL.</p>
  
  <p>The problem I'm having is that I get a concurrency exception thrown when I try to save data to the database.  If you examine the sql that is output to the console it tries to query the concurrency field from the database using the old value in the where clause.  Because this field has been updated by the database.</p>
  
  <p>Environment:</p>
  
  <ul>
  <li>Windows 7 64 bit</li>
  <li>Visual Studio 2013</li>
  </ul>
  
  <p>Nuget packages installed:</p>
  
  <ul>
  <li>EF 6.0.1</li>
  <li>MySql.ConnectorNET.Data 6.8.3.2 </li>
  <li>MySql.ConnectorNET.Entity 6.8.3.2</li>
  </ul>
  
  <p>Demo Database SQL:</p>
  
  <pre><code>DROP DATABASE IF EXISTS `bugreport`;
  CREATE DATABASE IF NOT EXISTS `bugreport`;
  USE `bugreport`;
  
  DROP TABLE IF EXISTS `test`;
  CREATE TABLE IF NOT EXISTS `test` (
    `TestId` int(10) NOT NULL AUTO_INCREMENT,
    `AStringField` varchar(50) DEFAULT NULL,
    `DateModified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`TestId`)
  ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
  
  INSERT INTO `test` (`TestId`, `AStringField`, `DateModified`) VALUES
      (1, 'Initial Value', '2014-07-11 09:15:52');
  </code></pre>
  
  <p>Demo code:</p>
  
  <pre><code>using System;
  using System.Data.Entity.Infrastructure;
  using System.Linq;
  using System.ComponentModel.DataAnnotations;
  using System.ComponentModel.DataAnnotations.Schema;
  using System.Data.Entity;
  
  namespace BugReport
  {
      class Program
      {
          static void Main(string[] args)
          {
              using (var context = new BugReportModel())
              {
                  context.Database.Log = (s =&gt; Console.WriteLine(s));
  
                  var firstTest = context.tests.First();
                  firstTest.AStringField = "First Value";
  
                  // Exception is thrown when changes are saved.
                  context.SaveChanges();              
  
                  Console.ReadLine();
              } 
          }
      }
  
      public class BugReportModel : DbContext
      {
          public BugReportModel()
              : base("name=Model1")
          {
  
          }
  
          public virtual DbSet&lt;test&gt; tests { get; set; }
      }
  
  
      [Table("test")]
      public class test
      {
          [Key]
          [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
          public int TestId { get; set; }
  
          [StringLength(50)]
          public string AStringField { get; set; }
  
          [ConcurrencyCheck()]
          [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
          [Column(TypeName = "timestamp")]
          public System.DateTime DateModified { get; set; }
      }
  }
  </code></pre>
  
  <p>Update:
  Filed <a href="http://bugs.mysql.com/bug.php?id=73271" rel="nofollow">bug</a> with MySql. </p>