Table of Contents

Interface IRelationalTransactionManager

Namespace
Microsoft.EntityFrameworkCore.Storage
Assembly
Microsoft.EntityFrameworkCore.Relational.dll

Creates and manages the current transaction for a relational database.

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

public interface IRelationalTransactionManager : IDbContextTransactionManager, IResettableService

Remarks

The service lifetime is Scoped. This means that each Microsoft.EntityFrameworkCore.DbContext instance will use its own instance of this service. The implementation may depend on other services registered with any lifetime. The implementation does not need to be thread-safe.

See Implementation of database providers and extensions for more information and examples.

Methods

BeginTransaction(IsolationLevel)

Begins a new transaction.

IDbContextTransaction BeginTransaction(IsolationLevel isolationLevel)

Parameters

isolationLevel IsolationLevel

The isolation level to use for the transaction.

Returns

IDbContextTransaction

The newly created transaction.

BeginTransactionAsync(IsolationLevel, CancellationToken)

Asynchronously begins a new transaction.

Task<IDbContextTransaction> BeginTransactionAsync(IsolationLevel isolationLevel, CancellationToken cancellationToken = default)

Parameters

isolationLevel IsolationLevel

The isolation level to use for the transaction.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task<IDbContextTransaction>

A task that represents the asynchronous operation. The task result contains the newly created transaction.

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

UseTransaction(DbTransaction?)

Specifies an existing DbTransaction to be used for database operations.

IDbContextTransaction? UseTransaction(DbTransaction? transaction)

Parameters

transaction DbTransaction

The transaction to be used.

Returns

IDbContextTransaction

An instance of IDbTransaction that wraps the provided transaction.

UseTransaction(DbTransaction?, Guid)

Specifies an existing DbTransaction to be used for database operations.

IDbContextTransaction? UseTransaction(DbTransaction? transaction, Guid transactionId)

Parameters

transaction DbTransaction

The transaction to be used.

transactionId Guid

The unique identifier for the transaction.

Returns

IDbContextTransaction

An instance of IDbTransaction that wraps the provided transaction.

UseTransactionAsync(DbTransaction?, Guid, CancellationToken)

Specifies an existing DbTransaction to be used for database operations.

Task<IDbContextTransaction?> UseTransactionAsync(DbTransaction? transaction, Guid transactionId, CancellationToken cancellationToken = default)

Parameters

transaction DbTransaction

The transaction to be used.

transactionId Guid

The unique identifier for the transaction.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task<IDbContextTransaction>

An instance of IDbTransaction that wraps the provided transaction.

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

UseTransactionAsync(DbTransaction?, CancellationToken)

Specifies an existing DbTransaction to be used for database operations.

Task<IDbContextTransaction?> UseTransactionAsync(DbTransaction? transaction, CancellationToken cancellationToken = default)

Parameters

transaction DbTransaction

The transaction to be used.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task<IDbContextTransaction>

An instance of IDbTransaction that wraps the provided transaction.

Exceptions

OperationCanceledException

If the CancellationToken is canceled.