-
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
Feature Request: Savepoints #20211
Comments
@Lobosque savepoints are a PostgreSQL-specific concept, or at least not a universal thing supported across database. For this reason, it isn't present in the ADO.NET API, and so we can't really add anything to EF Core generically. This would also be quite an effort, as the EF Core infrastructure currently knows about transactions succeeding or failing, and does not have a concept of partially rolling back a transaction (which is what savepoints allow). Note that you can extract the ADO DbTransaction from the RelationalTransaction instance, down-cast that to NpgsqlTransaction, and call those methods yourself - so you don't need to do ExecuteSqlRaw. |
I took a quick look and apparently most DBs do support some form of savepoints (PostgreSQL, SQL Server, Sqlite, MySQL). So we could expose something in ADO.NET for managing them (and after that possibly do something with that in EF), though we'd need to first investigate that semantics are consistent. |
@roji it is implemented accross all relevant databases and it looks like it is in the SQL standard. Shouldn't the issue be reopened so others could also show their interest and discuss the feature? |
I do agree there is potential here for a cross-database transaction savepoint API - but we'd add it to ADO.NET first in any case (so https://github.com/dotnet/runtime). We haven't seen any request for it up to now, but that doesn't mean we shouldn't have an issue for it. At the EF level, assuming support is added in ADO.NET we'd have to understand what it means to have savepoint support exactly. I agree it may make sense to use a savepoint when SaveUpdates is called and a transaction is already open (so that the entire transaction doesn't have to be rolled back in case of an error), but that's something that can only come significantly later. Reopening to discuss in triage. |
Opened dotnet/runtime#33397 to track adding savepoint APIs to System.Data.Common. Using savepoints as a fix for #20176 (rolling back on optimistic concurrency exceptions) can be tracked in that issue, so I don't think this issue can track anything else (except maybe adding sugar on RelationalTransaction to call the new savepoint APIs on DbTransaction, which seems pretty low value). |
Note that the proposal for System.Data support (dotnet/runtime#33397) is waiting to be reviewed and will probably make it into .NET 5.0. At the same time, full support for savepoints has already been merged for EF Core as well in #20176. Thanks for raising this issue! |
@roji thank you and the team for making it happen! |
Thank you for raising it and making the original suggestion! This probably wouldn't have happened otherwise...! |
Duplicate of #20176 |
Rollback a transaction up to a specific savepoint without
ExecuteSqlRaw
and without mannually re-arranging the ChangeTracker StateThe text was updated successfully, but these errors were encountered: