RelationalConnection Class

Definition

Represents a connection with a relational database.

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

C#
public abstract class RelationalConnection : IDisposable, Microsoft.EntityFrameworkCore.Storage.IDbContextTransactionManager, Microsoft.EntityFrameworkCore.Storage.IRelationalConnection
C#
public abstract class RelationalConnection : IDisposable, Microsoft.EntityFrameworkCore.Storage.IDbContextTransactionManager, Microsoft.EntityFrameworkCore.Storage.IRelationalConnection, Microsoft.EntityFrameworkCore.Storage.ITransactionEnlistmentManager
C#
public abstract class RelationalConnection : IAsyncDisposable, IDisposable, Microsoft.EntityFrameworkCore.Storage.IDbContextTransactionManager, Microsoft.EntityFrameworkCore.Storage.IRelationalConnection, Microsoft.EntityFrameworkCore.Storage.ITransactionEnlistmentManager
Inheritance
RelationalConnection
Implements

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 for more information and examples.

Constructors

Properties

ActiveCursor

Gets or sets the active cursor.

CommandTimeout

Gets the timeout for executing a command against the database.

ConnectionId

The unique identifier for this connection.

ConnectionString

Gets or sets the connection string for the database.

Context

The DbContext currently in use.

CurrentAmbientTransaction

The current ambient transaction. Defaults to Current.

CurrentTransaction

Gets the current transaction.

DbConnection

Gets or sets the underlying DbConnection used to connect to the database.

Dependencies

Relational provider-specific dependencies for this service.

EnlistedTransaction

The currently enlisted transaction.

IsMultipleActiveResultSetsEnabled

Gets a value indicating whether the multiple active result sets feature is enabled.

Logger

Gets the logger to write to.

Semaphore
Obsolete.

Gets a semaphore used to serialize access to this connection.

SupportsAmbientTransactions

Indicates whether the store connection supports ambient transactions

Methods

BeginTransaction()

Begins a new transaction.

BeginTransaction(IsolationLevel)

Begins a new transaction.

BeginTransactionAsync(CancellationToken)

Asynchronously begins a new transaction.

BeginTransactionAsync(IsolationLevel, CancellationToken)

Asynchronously begins a new transaction.

Close()

Closes the connection to the database.

CloseAsync()

Closes the connection to the database.

CloseDbConnection()

Template method that by default calls Close() but can be overridden by providers to make a different call instead.

CloseDbConnectionAsync()

Template method that by default calls CloseAsync() but can be overridden by providers to make a different call instead.

CommitTransaction()

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

CommitTransactionAsync(CancellationToken)

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

ConnectionBeginTransaction(IsolationLevel)

Template method that by default calls BeginDbTransaction(IsolationLevel) but can be overridden by providers to make a different call instead.

ConnectionBeginTransactionAsync(IsolationLevel, CancellationToken)

Template method that by default calls BeginDbTransactionAsync(IsolationLevel, CancellationToken) but can be overridden by providers to make a different call instead.

ConnectionEnlistTransaction(Transaction)

Template method that by default calls EnlistTransaction(Transaction) but can be overridden by providers to make a different call instead.

CreateDbConnection()

Creates a DbConnection to the database.

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.

DisposeDbConnection()

Template method that by default calls Dispose() but can be overridden by providers to make a different call instead.

DisposeDbConnectionAsync()

Template method that by default calls DisposeAsync() but can be overridden by providers to make a different call instead.

EnlistTransaction(Transaction)

Specifies an existing Transaction to be used for database operations.

GetValidatedConnectionString()

Returns the configured connection string only if it has been set or a valid DbConnection exists.

Open()

Opens the connection to the database.

Open(Boolean)

Opens the connection to the database.

OpenAsync(CancellationToken, Boolean)

Asynchronously opens the connection to the database.

OpenAsync(CancellationToken)

Asynchronously opens the connection to the database.

OpenDbConnection(Boolean)

Template method that by default calls Open() but can be overridden by providers to make a different call instead.

OpenDbConnectionAsync(Boolean, CancellationToken)

Template method that by default calls OpenAsync() but can be overridden by providers to make a different call instead.

RentCommand()

Rents a relational command that can be executed with this connection.

ResetState(Boolean)

Resets the connection state. Called by Dispose() and ResetState().

ResetStateAsync(Boolean)

Resets the connection state. Called by DisposeAsync() and ResetStateAsync(CancellationToken).

ReturnCommand(IRelationalCommand)

Returns a relational command to this connection, so that it can be reused in the future.

RollbackTransaction()

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

RollbackTransactionAsync(CancellationToken)

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

SetDbConnection(DbConnection, Boolean)

Sets the underlying DbConnection used to connect to the database.

UseTransaction(DbTransaction, Guid)

Specifies an existing DbTransaction to be used for database operations.

UseTransaction(DbTransaction)

Specifies an existing DbTransaction to be used for database operations.

UseTransactionAsync(DbTransaction, CancellationToken)

Specifies an existing DbTransaction to be used for database operations.

UseTransactionAsync(DbTransaction, Guid, CancellationToken)

Specifies an existing DbTransaction to be used for database operations.

Explicit Interface Implementations

Applies to

Product Versions
Entity Framework Core 1.0, 1.1, 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0