-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Optimistic concurrency exception from stored procedure logs error #29135
Comments
This wasn't a logging issue... It turns out that the technique we were using to return the concurrency token from the sproc was returning the original value (before the modification): BEGIN
UPDATE [Documents] SET
[Title] = @Title,
-- ...
[IssueNumber] = @IssueNumber,
[EditorId] = @EditorId,
@RetrievedOn = [RetrievedOn],
@RowVersion = [RowVersion]
WHERE [Id] = @Id AND [RowVersion] = @RowVersion_Original
SELECT @@ROWCOUNT;
END"); This was causing the previous update to return an out-of-date concurrency token, and for the 1st SaveChanges to fail with a concurrency exception, instead of the 2nd. That 1st SaveChanges is simply on (Note that this means we do log SaveChangesFailed for concurrency exceptions (here). As a fix, I'm changing the sproc definition to extract the new value of the concurrency token into a temp table (via OUTPUT INTO), and then set the output parameter to that. #29138 does this for the tests for 7.0, dotnet/EntityFramework.Docs#4038 does this for the sample fixes in the docs. Note that after this, the TPT scenario fails during seeding with the following error (regardless of whether sprocs are enabled or not). Let me know if you want me to take a look.
|
I just figured out this wasn't working at all and was going to ask you how to fix it. :-)
This is #29134 that I want you to review. As a workaround in the sample you can use |
Ah great, that's merged in now so all should be good. |
Test with https://github.com/dotnet/EntityFramework.Docs/blob/274255cff5c7d38045ad0d15a6454e199e072f2c/samples/core/Miscellaneous/NewInEFCore7/DocumentsContext.cs#L74
Normally, a
DbUpdateConcurrencyException
does not result in an error being logged.But when using stored procedures, a "fail" message is logged:
The text was updated successfully, but these errors were encountered: