-
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
Support SELECT FOR UPDATE / UPDLOCK (pessimistic concurrency) #26042
Comments
This may be covered by #6717, and may be achievable today by using raw SQL and composing your LINQ operators over it (see the docs), assuming SQL Server allows SELECT FOR UPDATE in a subquery. |
Note: use table annotations to represent this (#26858). |
Cross-database investigation on
|
Another use case is |
For anyone who can't wait for this feature, check out this simple command interceptor or try Linq2Db. |
Another use-case: atomically update something with ExecuteUpdate. This can be done today with optimistic locking, but that requires retrying when the update fails; that means some sort of random delay + backoff strategy is needed, where pessimistic locking can solve this much more easily. |
I want to garantee that only one Api Request (Database Transaction) can modify an entity at a given time. this could be done by selecting a row with "SELECT FOR UPDATE" inside a transaction.
Something like:
Would generate something like:
I think that EF itself does not need to track at any level that the entity was selected with a table hint, it only need to be able to express the SQL.
The text was updated successfully, but these errors were encountered: