Share via


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.

public abstract class RelationalConnection : IDisposable, Microsoft.EntityFrameworkCore.Storage.IDbContextTransactionManager, Microsoft.EntityFrameworkCore.Storage.IRelationalConnection
public abstract class RelationalConnection : IDisposable, Microsoft.EntityFrameworkCore.Storage.IDbContextTransactionManager, Microsoft.EntityFrameworkCore.Storage.IRelationalConnection, Microsoft.EntityFrameworkCore.Storage.ITransactionEnlistmentManager
public abstract class RelationalConnection : IAsyncDisposable, IDisposable, Microsoft.EntityFrameworkCore.Storage.IDbContextTransactionManager, Microsoft.EntityFrameworkCore.Storage.IRelationalConnection, Microsoft.EntityFrameworkCore.Storage.ITransactionEnlistmentManager
type RelationalConnection = class
    interface IRelationalConnection
    interface IRelationalTransactionManager
    interface IDbContextTransactionManager
    interface IDisposable
type RelationalConnection = class
    interface IRelationalConnection
    interface IRelationalTransactionManager
    interface IDbContextTransactionManager
    interface IResettableService
    interface IDisposable
type RelationalConnection = class
    interface IRelationalConnection
    interface IRelationalTransactionManager
    interface IDbContextTransactionManager
    interface IResettableService
    interface IDisposable
    interface ITransactionEnlistmentManager
type RelationalConnection = class
    interface IRelationalConnection
    interface IRelationalTransactionManager
    interface IDbContextTransactionManager
    interface IResettableService
    interface IDisposable
    interface IAsyncDisposable
    interface ITransactionEnlistmentManager
Public MustInherit Class RelationalConnection
Implements IDbContextTransactionManager, IDisposable, IRelationalConnection
Public MustInherit Class RelationalConnection
Implements IDbContextTransactionManager, IDisposable, IRelationalConnection, ITransactionEnlistmentManager
Public MustInherit Class RelationalConnection
Implements IAsyncDisposable, IDbContextTransactionManager, IDisposable, IRelationalConnection, 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

RelationalConnection(IDbContextOptions, ILogger)

Initializes a new instance of the IRelationalConnection class.

RelationalConnection(RelationalConnectionDependencies)

Initializes a new instance of the RelationalConnection class.

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

IRelationalConnection.RegisterBufferable(IBufferable)

Registers a potentially bufferable active query.

IRelationalConnection.RegisterBufferableAsync(IBufferable, CancellationToken)

Asynchronously registers a potentially bufferable active query.

IResettableService.ResetState()
IResettableService.ResetStateAsync(CancellationToken)

Applies to