Table of Contents

Interface IDbContextTransactionManager

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

Creates and manages the current transaction.

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

public interface IDbContextTransactionManager : IResettableService
Inherited Members

Remarks

The service lifetime is Scoped. This means that each 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 and Transactions in EF Core for more information and examples.

Properties

CurrentTransaction

Gets the current transaction.

IDbContextTransaction? CurrentTransaction { get; }

Property Value

IDbContextTransaction

Methods

BeginTransaction()

Begins a new transaction.

IDbContextTransaction BeginTransaction()

Returns

IDbContextTransaction

The newly created transaction.

BeginTransactionAsync(CancellationToken)

Asynchronously begins a new transaction.

Task<IDbContextTransaction> BeginTransactionAsync(CancellationToken cancellationToken = default)

Parameters

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.

CommitTransaction()

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

void CommitTransaction()

CommitTransactionAsync(CancellationToken)

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

Task CommitTransactionAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

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

Returns

Task

A task that represents the asynchronous operation.

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

RollbackTransaction()

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

void RollbackTransaction()

RollbackTransactionAsync(CancellationToken)

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

Task RollbackTransactionAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

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

Returns

Task

A task that represents the asynchronous operation.

Exceptions

OperationCanceledException

If the CancellationToken is canceled.