RelationalTransaction Class

Definition

A transaction against the database.

Instances of this class are typically obtained from BeginTransaction() and it is not designed to be directly constructed in your application code.

public class RelationalTransaction : IDisposable, Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.Data.Common.DbTransaction>, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction
public class RelationalTransaction : IAsyncDisposable, IDisposable, Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.Data.Common.DbTransaction>, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction
type RelationalTransaction = class
    interface IDbContextTransaction
    interface IDisposable
    interface IInfrastructure<DbTransaction>
type RelationalTransaction = class
    interface IDbContextTransaction
    interface IDisposable
    interface IAsyncDisposable
    interface IInfrastructure<DbTransaction>
Public Class RelationalTransaction
Implements IDbContextTransaction, IDisposable, IInfrastructure(Of DbTransaction)
Public Class RelationalTransaction
Implements IAsyncDisposable, IDbContextTransaction, IDisposable, IInfrastructure(Of DbTransaction)
Inheritance
RelationalTransaction
Implements

Remarks

See Transactions in EF Core for more information.

Constructors

RelationalTransaction(IRelationalConnection, DbTransaction, Guid, IDiagnosticsLogger<DbLoggerCategory.Database>, Boolean)

Initializes a new instance of the RelationalTransaction class.

RelationalTransaction(IRelationalConnection, DbTransaction, Guid, IDiagnosticsLogger<DbLoggerCategory.Database>, Boolean, ISqlGenerationHelper)

Initializes a new instance of the RelationalTransaction class.

RelationalTransaction(IRelationalConnection, DbTransaction, IDiagnosticsLogger<DbLoggerCategory.Database>, Boolean)

Initializes a new instance of the RelationalTransaction class.

RelationalTransaction(IRelationalConnection, DbTransaction, ILogger, Boolean)

Initializes a new instance of the RelationalTransaction class.

Properties

Connection

The connection.

Logger

The logger.

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.

TransactionId

A correlation ID that allows this transaction to be identified and correlated across multiple database calls.

Methods

ClearTransaction()

Remove the underlying transaction from the connection

ClearTransactionAsync(CancellationToken)

Remove the underlying transaction from the connection

Commit()

Commits all changes made to the database in the current transaction.

CommitAsync(CancellationToken)

Commits all changes made to the database in the current transaction asynchronously.

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.

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.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

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.

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.

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.

ReleaseSavepoint(String)

Destroys a savepoint previously defined in the current transaction. This allows the system to reclaim some resources before the transaction ends.

If savepoint release isn't supported, ReleaseSavepoint(String) and ReleaseSavepointAsync(String, CancellationToken) should do nothing rather than throw. This is the default behavior.

ReleaseSavepointAsync(String, CancellationToken)

Destroys a savepoint previously defined in the current transaction. This allows the system to reclaim some resources before the transaction ends.

If savepoint release isn't supported, ReleaseSavepoint(String) and ReleaseSavepointAsync(String, CancellationToken) should do nothing rather than throw. This is the default behavior.

Rollback()

Discards all changes made to the database in the current transaction.

RollbackAsync(CancellationToken)

Discards all changes made to the database in the current transaction asynchronously.

RollbackToSavepoint(String)

Rolls back all commands that were executed after the specified savepoint was established.

RollbackToSavepointAsync(String, CancellationToken)

Rolls back all commands that were executed after the specified savepoint was established.

Explicit Interface Implementations

IInfrastructure<DbTransaction>.Instance

Extension Methods

GetInfrastructure<T>(IInfrastructure<T>)

Gets the value from a property that is being hidden using IInfrastructure<T>.

This method is typically used by database providers (and other extensions). It is generally not used in application code.

IInfrastructure<T> is used to hide properties that are not intended to be used in application code but can be used in extension methods written by database providers etc.

GetDbTransaction(IDbContextTransaction)

Gets the underlying DbTransaction for the given transaction. Throws if the database being targeted is not a relational database that uses DbTransaction.

Applies to