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

Provide a way to force ef to check ConcurrencyToken #18536

Open
Tracked by #14496
crclz opened this issue Oct 23, 2019 · 3 comments
Open
Tracked by #14496

Provide a way to force ef to check ConcurrencyToken #18536

crclz opened this issue Oct 23, 2019 · 3 comments

Comments

@crclz
Copy link

crclz commented Oct 23, 2019

problem

When saving changes, EFCore only checks the concurrency token of a row when the entity is modified. Consider the folowing situation:

First I fetch record p. I'm not going to modify record p, but I want to ensure record p is unchanged until savechanges(). (like a SHARE lock)

solution

Force efcore to check the ConcurrencyToken of an entity. Maybe by executing SELECT 1 FROM students WHERE student_id=11 AND concurrency_token=55 FOR SHARE and throw exception if null is returned.

@ajcvickers
Copy link
Member

Note from triage: Putting on the backlog to consider.

@crclz The only workaround I can come up with at the moment is to mark either the entire entity or some property as modified even when it isn't. This isn't great of course, because it will cause updates when they aren't needed.

@crclz
Copy link
Author

crclz commented Oct 26, 2019

@ajcvickers Yes, marking the whole or a part of the entity is not a good solution. Not only because it does unneeded updates, but also because it uses EXCLUSIVE lock when SHARE lock is ok, which increase the possibility of transaction failure (concurrency violation) and decreases throughput.
Additionally, some feature of efcore make it quite fit for DDD(Domain Driven Design), but now it seems there is not an eazy way for EFCore to guarantee the consistency within an aggregate root.

@AndriySvyryd
Copy link
Member

@crclz Aggregate optimistic concurrency is tracked by #18529

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

3 participants