Skip to content
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

Elaborate on concurrency tokens in detached use cases #860

Open
thomasdc opened this issue Jul 24, 2018 — with docs.microsoft.com · 5 comments
Open

Elaborate on concurrency tokens in detached use cases #860

thomasdc opened this issue Jul 24, 2018 — with docs.microsoft.com · 5 comments

Comments

Copy link

When you're updating an entity in a detached situation (e.g. MVC or SPA) and want to make use of a concurrency token, it's important to set the OriginalValue of a concurrency token to the CurrentValue as mentioned on https://docs.microsoft.com/en-us/aspnet/core/data/ef-rp/concurrency?view=aspnetcore-2.1&tabs=visual-studio. It took me several hours to realise this. It might help others if this situation was elaborated on this page.

    // Update the RowVersion to the value when this entity was
    // fetched. If the entity has been updated after it was
    // fetched, RowVersion won't match the DB RowVersion and
    // a DbUpdateConcurrencyException is thrown.
    // A second postback will make them match, unless a new 
    // concurrency issue happens.
    _context.Entry(departmentToUpdate)
        .Property("RowVersion").OriginalValue = Department.RowVersion;

Document Details

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

Copy link

It seems the example above is incorrect. The concurrency token is LastName and the update that is supposed to trigger the concurrency exception is updating the FirstName. Or am I missing something?

@thomasdc
Copy link
Author

That's correct in this case. The example code was copy pasted from another documentation page. However, the same principle applies.

@VictorioBerra
Copy link

I also spent way too long today struggling with this until I found a stack overflow post showing Original Value.

Can someone explain why we need to manually manipulate the original value to enable this functionality? Why won't it use whatever value is on the entity?

@divega divega added the help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. label Feb 21, 2019
@ajcvickers ajcvickers added area-optimistic-concurrency type-enhancement and removed help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. labels Aug 28, 2019
@ajcvickers ajcvickers added this to the Backlog milestone Aug 28, 2019
@ajcvickers
Copy link
Member

See also dotnet/efcore#18505

@ajcvickers
Copy link
Member

See also: dotnet/efcore#27865

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants