Bug #80033 .Net EF Optimistic Concurrence not working
Submitted: 18 Jan 2016 14:59 Modified: 27 Jan 2016 10:54
Reporter: Marco Niedermeyer Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:6.9.8 OS:Windows
Assigned to: CPU Architecture:Any
Tags: ConcurrencyCheck, DatabaseGenerated, entity framework

[18 Jan 2016 14:59] Marco Niedermeyer
Description:
I think i used the best practice for that scenario. (details: see "How to repeat"):
I added a Column "RowVersion" to the table "beleg".
When i try to update a row throught Entity Framework i get a DbUpdateConcurrencyException which should happen when concurrence is violated.
These are the statements which get processed by the MySql Server (Copied from Log)

Init DB	[DTABASENAME]
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ
BEGIN
UPDATE `Beleg` SET `Modified_At`='2016-01-18 15:43:55.538835', `LAnschrift4`='4444' WHERE (`Id` = '7e1209fd-045a-11e5-aa33-00155d02b507') AND (`RowVersion` = '2016-01-18 15:35:14 ');
SELECT `RowVersion` FROM `Beleg` WHERE  row_count() > 0 and (`Id` = '7e1209fd-045a-11e5-aa33-00155d02b507') AND (`RowVersion` = '2016-01-18 15:35:14 ')
ROLLBACK

Error message:
"
Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions.
"

I would have expected something like 
UPDATE `Beleg` SET `Modified_At`='2016-01-18 15:43:55.538835', `LAnschrift4`='4444', `RowVersion` = Now() WHERE (`Id` = '7e1209fd-045a-11e5-aa33-00155d02b507') AND (`RowVersion` = '2016-01-18 15:35:14 ');

The DateTime is correct.
When i use the Workbench to submit just the update statement it works.

Thank oyu

How to repeat:
DataBase: 
---------
ALTER TABLE `beleg` 
ADD COLUMN `RowVersion` DATETIME NULL COMMENT '' AFTER `modified_at`;

update `beleg` set RowVersion = Now();

ALTER TABLE `beleg` 
CHANGE COLUMN `RowVersion` `RowVersion` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '' ;

Model:
---------
[ConcurrencyCheck]
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public DateTime RowVersion { get; set; }

How To:
Use EF 6, Code First
Update a Model.
SaveChanges() to DataContext
--> Exception
[19 Jan 2016 10:16] Marco Niedermeyer
Installed Programs:
"MySQL Connector NET 6.9.8"
"MySQL for Visual Studio 1.2.5"
"MySQL Workbench 6.3. CE"

NuGet Packages installed in VS 2015 Pro:
"EntityFramework" v6.1.3 by Microsoft
"MySql.Data" v6.9.8 by Oracle
"MySql.Data.Entity" v6.9.8 by Oracle

Database (installed on server):
MySQL Workbench Community (GPL) for Windows version 6.3.4  revision 0 build 828 (64 bit)
[19 Jan 2016 10:35] Marco Niedermeyer
Sorry for wrong Database
SELECT VERSION() delivers "5.6.26-log"
[20 Jan 2016 7:17] Chiranjeevi Battula
Hello Marco Niedermeyer,

Thank you for the bug report.
This is most likely duplicate of Bug #73271, please see Bug #73271.

Thanks,
Chiranjeevi.
[20 Jan 2016 7:47] Marco Niedermeyer
Yes i found that one before (as you can see in my tags)
That Bug is 6 months old and the patch is for a different version (i did not try it).
I assumed the fix would have already found its way into the main branch.
That is why i started a new one.

What should i do?
[27 Jan 2016 10:54] Marco Niedermeyer
Hello there...

Any news yet for an updated patch or if the old one is compatible?

Thank you
[23 Jun 2016 11:15] Hendrik Csallner
Hello Chiranjeevi, hello everybody!

Is there any reason why the questions

1) if the patch for EF-Connector 6.9.6 is also usable for 6.9.8, or
2) if there is an updated patch for 6.9.8, and
3) if this patch is working, why it has not come into version 6.9.8?

are ignored?

And why also the "original" bug #73271 (posted almost 2 years ago, with a patch offered about 1 year ago) is still unsolved (status "Analysing") ??

Thanks for answers.