简体   繁体   中英

Entity Framework 6 with MySql Concurrency Token not working

I have an EF6 model using this database table:

CREATE TABLE `person` (
`id` INT(11) NOT NULL,
`last_modified` TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
`birth_date` DATE NULL DEFAULT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `FK_PERSON_person_id` FOREIGN KEY (`id`) REFERENCES `person_id` 
(`id`)
)
COLLATE='utf8mb4_bin'
ENGINE=InnoDB;

In the code-first Map class specifies

Property(t => t.LastModified)
    .IsConcurrencyToken()
    .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);

I am updating the database from a detached model using GraphDiff which correctly determines that the birth_date field has changed and flags the Person model as modified.

When I execute ctx.SaveChanges the update fails with a concurrency error and the database log shows the following :

2017-11-06T14:18:00.896200Z   183 Query SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ
2017-11-06T14:18:00.896200Z   183 Query BEGIN
2017-11-06T14:18:00.897200Z   183 Query UPDATE `person` SET `birth_date`='1973-03-28 00:00:00 ' WHERE (`id` = 1) AND (`last_modified` = '2017-10-17 08:36:44.586000');
2017-11-06T14:18:00.897200Z   183 Query SELECT
`last_modified`
FROM `person`
 WHERE  row_count() > 0 and (`id` = 1) AND (`last_modified` = '2017-10-17 08:36:44.586000')
2017-11-06T14:18:00.898200Z   183 Query ROLLBACK

The UPDATE has completed correctly and the last_modified value was correct but will have been changed by the successful update. The following SELECT statement is problematic. I assume its purpose is to update the in-memory model with the new last_modified date. Unfortunately it explicitly requires the old timestamp and fails to return any records which kills the transaction.

Why is this happening and how can I get the intended operation?

Thanks, Andy

Please see a possible bug report

https://bugs.mysql.com/bug.php?id=73271

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM