Interface IDbContextTransaction
- Namespace
- Microsoft.EntityFrameworkCore.Storage
- Assembly
- Microsoft.EntityFrameworkCore.dll
A transaction against the database.
public interface IDbContextTransaction : IDisposable, IAsyncDisposable
- Inherited Members
Remarks
Instances of this class are typically obtained from BeginTransaction() and it is not designed to be directly constructed in your application code.
See Transactions in EF Core for more information and examples.
Properties
SupportsSavepoints
Gets a value that indicates whether this IDbContextTransaction instance supports database savepoints. If false, the methods CreateSavepointAsync(string, CancellationToken), RollbackToSavepointAsync(string, CancellationToken) and ReleaseSavepointAsync(string, CancellationToken) as well as their synchronous counterparts are expected to throw NotSupportedException.
bool SupportsSavepoints { get; }
Property Value
- bool
true if this IDbContextTransaction instance supports database savepoints; otherwise, false.
Remarks
See Transactions in EF Core for more information and examples.
TransactionId
Gets the transaction identifier.
Guid TransactionId { get; }
Property Value
Remarks
See Transactions in EF Core for more information and examples.
Methods
Commit()
Commits all changes made to the database in the current transaction.
void Commit()
Remarks
See Transactions in EF Core for more information and examples.
CommitAsync(CancellationToken)
Commits all changes made to the database in the current transaction asynchronously.
Task CommitAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
Remarks
See Transactions in EF Core for more information and examples.
Exceptions
- OperationCanceledException
If the CancellationToken is canceled.
CreateSavepoint(string)
Creates a savepoint in the transaction. This allows all commands that are executed after the savepoint was established to be rolled back, restoring the transaction state to what it was at the time of the savepoint.
void CreateSavepoint(string name)
Parameters
name
stringThe name of the savepoint to be created.
Remarks
See Transactions in EF Core for more information and examples.
CreateSavepointAsync(string, CancellationToken)
Creates a savepoint in the transaction. This allows all commands that are executed after the savepoint was established to be rolled back, restoring the transaction state to what it was at the time of the savepoint.
Task CreateSavepointAsync(string name, CancellationToken cancellationToken = default)
Parameters
name
stringThe name of the savepoint to be created.
cancellationToken
CancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
Remarks
See Transactions in EF Core for more information and examples.
Exceptions
- OperationCanceledException
If the CancellationToken is canceled.
ReleaseSavepoint(string)
Destroys a savepoint previously defined in the current transaction. This allows the system to reclaim some resources before the transaction ends.
void ReleaseSavepoint(string name)
Parameters
name
stringThe name of the savepoint to release.
Remarks
If savepoint release isn't supported, ReleaseSavepoint(string) and ReleaseSavepointAsync(string, CancellationToken) should do nothing rather than throw. This is the default behavior.
See Transactions in EF Core for more information and examples.
ReleaseSavepointAsync(string, CancellationToken)
Destroys a savepoint previously defined in the current transaction. This allows the system to reclaim some resources before the transaction ends.
Task ReleaseSavepointAsync(string name, CancellationToken cancellationToken = default)
Parameters
name
stringThe name of the savepoint to release.
cancellationToken
CancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
Remarks
If savepoint release isn't supported, ReleaseSavepoint(string) and ReleaseSavepointAsync(string, CancellationToken) should do nothing rather than throw. This is the default behavior.
See Transactions in EF Core for more information and examples.
Exceptions
- OperationCanceledException
If the CancellationToken is canceled.
Rollback()
Discards all changes made to the database in the current transaction.
void Rollback()
Remarks
See Transactions in EF Core for more information and examples.
RollbackAsync(CancellationToken)
Discards all changes made to the database in the current transaction asynchronously.
Task RollbackAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
Remarks
See Transactions in EF Core for more information and examples.
Exceptions
- OperationCanceledException
If the CancellationToken is canceled.
RollbackToSavepoint(string)
Rolls back all commands that were executed after the specified savepoint was established.
void RollbackToSavepoint(string name)
Parameters
name
stringThe name of the savepoint to roll back to.
Remarks
See Transactions in EF Core for more information and examples.
RollbackToSavepointAsync(string, CancellationToken)
Rolls back all commands that were executed after the specified savepoint was established.
Task RollbackToSavepointAsync(string name, CancellationToken cancellationToken = default)
Parameters
name
stringThe name of the savepoint to roll back to.
cancellationToken
CancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
Remarks
See Transactions in EF Core for more information and examples.
Exceptions
- OperationCanceledException
If the CancellationToken is canceled.