Class RelationalTransaction
- Namespace
- Microsoft.EntityFrameworkCore.Storage
- Assembly
- Microsoft.EntityFrameworkCore.Relational.dll
A transaction against the database.
Instances of this class are typically obtained from Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.BeginTransaction and it is not designed to be directly constructed in your application code.
public class RelationalTransaction : IDbContextTransaction, IDisposable, IAsyncDisposable, IInfrastructure<DbTransaction>
- Inheritance
-
RelationalTransaction
- Implements
-
IDbContextTransactionIInfrastructure<DbTransaction>
- Inherited Members
Constructors
RelationalTransaction(IRelationalConnection, DbTransaction, Guid, IDiagnosticsLogger<Transaction>, bool)
Initializes a new instance of the RelationalTransaction class.
public RelationalTransaction(IRelationalConnection connection, DbTransaction transaction, Guid transactionId, IDiagnosticsLogger<DbLoggerCategory.Database.Transaction> logger, bool transactionOwned)
Parameters
connection
IRelationalConnectionThe connection to the database.
transaction
DbTransactionThe underlying DbTransaction.
transactionId
GuidThe correlation ID for the transaction.
logger
IDiagnosticsLogger<Transaction>The logger to write to.
transactionOwned
boolA value indicating whether the transaction is owned by this class (i.e. if it can be disposed when this class is disposed).
Properties
Connection
The connection.
protected virtual IRelationalConnection Connection { get; }
Property Value
Logger
The logger.
protected virtual IDiagnosticsLogger<DbLoggerCategory.Database.Transaction> Logger { get; }
Property Value
- IDiagnosticsLogger<Transaction>
SupportsSavepoints
public virtual bool SupportsSavepoints { get; }
Property Value
TransactionId
public virtual Guid TransactionId { get; }
Property Value
Methods
ClearTransaction()
Remove the underlying transaction from the connection
protected virtual void ClearTransaction()
ClearTransactionAsync(CancellationToken)
Remove the underlying transaction from the connection
protected virtual Task ClearTransactionAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationToken
Returns
Commit()
public virtual void Commit()
CommitAsync(CancellationToken)
public virtual Task CommitAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationToken
Returns
CreateSavepoint(string)
public virtual void CreateSavepoint(string name)
Parameters
name
string
CreateSavepointAsync(string, CancellationToken)
public virtual Task CreateSavepointAsync(string name, CancellationToken cancellationToken = default)
Parameters
name
stringcancellationToken
CancellationToken
Returns
Dispose()
public virtual void Dispose()
DisposeAsync()
public virtual ValueTask DisposeAsync()
Returns
GetCreateSavepointSql(string)
When implemented in a provider supporting transaction savepoints, this method should return an SQL statement which creates a savepoint with the given name.
protected virtual string GetCreateSavepointSql(string name)
Parameters
name
stringThe name of the savepoint to be created.
Returns
- string
An SQL string to create the savepoint.
GetReleaseSavepointSql(string)
When implemented in a provider supporting transaction savepoints, this method should return an SQL statement which releases a savepoint with the given name.
If savepoint release isn't supported, ReleaseSavepoint(string) and ReleaseSavepointAsync(string, CancellationToken) should be overridden to do nothing.
protected virtual string GetReleaseSavepointSql(string name)
Parameters
name
stringThe name of the savepoint to be created.
Returns
- string
An SQL string to create the savepoint.
GetRollbackToSavepointSql(string)
When implemented in a provider supporting transaction savepoints, this method should return an SQL statement which rolls back a savepoint with the given name.
protected virtual string GetRollbackToSavepointSql(string name)
Parameters
name
stringThe name of the savepoint to be created.
Returns
- string
An SQL string to create the savepoint.
ReleaseSavepoint(string)
public virtual void ReleaseSavepoint(string name)
Parameters
name
string
ReleaseSavepointAsync(string, CancellationToken)
public virtual Task ReleaseSavepointAsync(string name, CancellationToken cancellationToken = default)
Parameters
name
stringcancellationToken
CancellationToken
Returns
Rollback()
public virtual void Rollback()
RollbackAsync(CancellationToken)
public virtual Task RollbackAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationToken
Returns
RollbackToSavepoint(string)
public virtual void RollbackToSavepoint(string name)
Parameters
name
string
RollbackToSavepointAsync(string, CancellationToken)
public virtual Task RollbackToSavepointAsync(string name, CancellationToken cancellationToken = default)
Parameters
name
stringcancellationToken
CancellationToken