New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ConcurrencyCheck + DatabaseGeneratedOption.Computed #23
Conversation
…-DateTime fields)
Hi, thank you for submitting this pull request. In order to consider your code we need you to sign the Oracle Contribution Agreement (OCA). Please review the details and follow the instructions at http://www.oracle.com/technetwork/community/oca-486395.html |
A minor fix to this PR ... In the unit test |
Sent OCA. |
TIMESTAMP Solution?I'm also investigating how to performing optimistic locking with a TIMESTAMP field. Firstly, you need to use a more fine grained timestamp value. So for example if you use the following, your timestamp value will be truncated to the nearest second (not very safe for optimistic locking).
Instead you should use following to record microsecond precision.
Secondly, I'm observing a bug that I'm reproducing within the environment of the MySQL .NET Connector unit test suite combined with the PR patch I've just submitted. EF6 now generates the correct optimistic locking SQL to perform an UPDATE followed by the SELECT (now fixed) that returns the updated TIMESTAMP field. However the MySQL connector returns a zero TIMESTAMP (0000-00-00 00:00:00.000000) even though executing the exact same UPDATE and SELECT in MySQL Workbench it returns a valid non-zero TIMESTAMP value. I've observed the packets read via the connection socket return the string '0000-00-00 00:00:00.000000' so its probably related to the MySQL session configuration in some way. Hints welcome! I'm currently testing this with MySQL v5.6.26 (Windows). It might be fixed in a more recent MySQL server version. |
I've spent some time this past week investigating why
with a trigger
However I still observe the same result (SELECT UpdatedAt returns a ZERO datetime after the trigger should have run). I've run this inside a transaction set to
So I suspect something in this test environment is setting the wrong isolation level. The default isolation level for EF6 with SQL Server is ReadUncommitted. Due my project commitments, I won't be submitting a further PR for the TIMESTAMP issue at this time. |
Hi, thank you for your contribution. Please confirm this code is submitted under the terms of the OCA (Oracle's Contribution Agreement) you have previously signed by cutting and pasting the following text as a comment: |
I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it. |
Hi, thank you for your contribution. Your code has been assigned to an internal queue. Please follow |
Will this fix become part of 6.10.x ? |
Sadly this critical fix never made it into the next release and so it was lost! |
Optimistic locking via a database generated field has been regularly reported as an issue and awaiting a fix for over 2.5 years now. It's required whenever you need to perform optimistic locking with an external non-EF application.
The bug reports below all use a Timestamp (DateTime) field which I think can fail due to rounding when converting C# DateTime => MySQL timestamp or datetime. So in the unit tests I've instead used a
BIGINT RowVersion
column with using a BEFORE UPDATE trigger to increment the field.Example:
NOTE: I've replace
row_count() > 0
withrow_count() = 1
as this also checks that the Id is unique.I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.