Table of Contents

Interface IRelationalConnection

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

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.

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.

public interface IRelationalConnection : IRelationalTransactionManager, IDbContextTransactionManager, IResettableService, IDisposable, IAsyncDisposable
Inherited Members

Properties

CommandTimeout

Gets the timeout for executing a command against the database.

int? CommandTimeout { get; set; }

Property Value

int?

ConnectionId

Gets the connection identifier.

Guid ConnectionId { get; }

Property Value

Guid

ConnectionString

Gets or sets the connection string for the database.

string ConnectionString { get; set; }

Property Value

string

Context

The Microsoft.EntityFrameworkCore.DbContext currently in use, or null if not known.

DbContext Context { get; }

Property Value

DbContext

CurrentTransaction

Gets the current transaction.

IDbContextTransaction CurrentTransaction { get; }

Property Value

IDbContextTransaction

DbConnection

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

The connection can only be changed when the existing connection, if any, is not open.

Note that the connection must be disposed by application code since it was not created by Entity Framework.

DbConnection DbConnection { get; set; }

Property Value

DbConnection

Semaphore

Gets a semaphore used to serialize access to this connection.

[Obsolete("EF Core no longer uses this semaphore. It will be removed in an upcoming release.")]
SemaphoreSlim Semaphore { get; }

Property Value

SemaphoreSlim

The semaphore.

Methods

Close()

Closes the connection to the database.

bool Close()

Returns

bool

true if the underlying connection was actually closed; false otherwise.

CloseAsync()

Closes the connection to the database.

Task<bool> CloseAsync()

Returns

Task<bool>

A task that represents the asynchronous operation, with a value of true if the connection was actually closed.

Open(bool)

Opens the connection to the database.

bool Open(bool errorsExpected = false)

Parameters

errorsExpected bool

Indicate if the connection errors are expected and should be logged as debug message.

Returns

bool

true if the underlying connection was actually opened; false otherwise.

OpenAsync(CancellationToken, bool)

Asynchronously opens the connection to the database.

Task<bool> OpenAsync(CancellationToken cancellationToken, bool errorsExpected = false)

Parameters

cancellationToken CancellationToken

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

errorsExpected bool

Indicate if the connection errors are expected and should be logged as debug message.

Returns

Task<bool>

A task that represents the asynchronous operation, with a value of true if the connection was actually opened.