dotnet / dotnet/EntityFramework.Docs

Clarify requirements for optimistic concurrency when using stored procs

Open
#1,101 1 comment 0 reactions 0 assignees View on GitHub
area-optimistic-concurrency
Dominant language
Mermaid
Stars
1.7k
Forks
2k
Avg merge
7d 23h
Merged PRs (30d)
16

Description

In the example of "class and update stored procedure with a timestamp concurrency token", it fails with ConcurrencyException - "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.". On debugging, it was found that UPDATE PROC must return/select updated Timestamp, else fails with concurrency. You need to add the following to the PROC to make it work successfully.

select [Timestamp] from [dbo].[Blogs] WHERE BlogId = @BlogId

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: e2c8d490-ce49-c4e6-8acb-13794d3f4c42
* Version Independent ID: 70120e6f-10b5-8154-f998-bf047e4b96a0
* Content: [Code First Insert, Update, and Delete Stored Procedures - EF6](https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/fluent/cud-stored-procedures)
* Content Source: [entity-framework/ef6/modeling/code-first/fluent/cud-stored-procedures.md](https://github.com/aspnet/EntityFramework.Docs/blob/master/entity-framework/ef6/modeling/code-first/fluent/cud-stored-procedures.md)
* Product: **entity-framework**
* GitHub Login: @divega
* Microsoft Alias: **divega**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.