Table of Contents

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
IDbContextTransaction
IInfrastructure<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 IRelationalConnection

The connection to the database.

transaction DbTransaction

The underlying DbTransaction.

transactionId Guid

The correlation ID for the transaction.

logger IDiagnosticsLogger<Transaction>

The logger to write to.

transactionOwned bool

A 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

IRelationalConnection

Logger

The logger.

protected virtual IDiagnosticsLogger<DbLoggerCategory.Database.Transaction> Logger { get; }

Property Value

IDiagnosticsLogger<Transaction>

SupportsSavepoints

public virtual bool SupportsSavepoints { get; }

Property Value

bool

TransactionId

public virtual Guid TransactionId { get; }

Property Value

Guid

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

Task

Commit()

public virtual void Commit()

CommitAsync(CancellationToken)

public virtual Task CommitAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task

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 string
cancellationToken CancellationToken

Returns

Task

Dispose()

public virtual void Dispose()

DisposeAsync()

public virtual ValueTask DisposeAsync()

Returns

ValueTask

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 string

The 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 string

The 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 string

The 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 string
cancellationToken CancellationToken

Returns

Task

Rollback()

public virtual void Rollback()

RollbackAsync(CancellationToken)

public virtual Task RollbackAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task

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 string
cancellationToken CancellationToken

Returns

Task