Table of Contents

Interface IAsyncDbConnection

Namespace
LinqToDB.Async
Assembly
linq2db.dll

Wrapper over DbConnection instance which contains all operations that could have custom implementation like:

public interface IAsyncDbConnection : IDisposable, IAsyncDisposable
Inherited Members
Extension Methods

Properties

Connection

Gets underlying connection instance.

DbConnection Connection { get; }

Property Value

DbConnection

ConnectionString

Gets or sets the string used to open the connection.

string ConnectionString { get; set; }

Property Value

string

The connection string used to establish the initial connection. The exact contents of the connection string depend on the specific data source for this connection. The default value is an empty string.

State

Gets a string that describes the state of the connection.

ConnectionState State { get; }

Property Value

ConnectionState

The state of the connection. The format of the string returned depends on the specific type of connection you are using.

Methods

BeginTransaction()

Starts new transaction for current connection with default isolation level.

IAsyncDbTransaction BeginTransaction()

Returns

IAsyncDbTransaction

Database transaction object.

BeginTransaction(IsolationLevel)

Starts new transaction for current connection with specified isolation level.

IAsyncDbTransaction BeginTransaction(IsolationLevel isolationLevel)

Parameters

isolationLevel IsolationLevel

Transaction isolation level.

Returns

IAsyncDbTransaction

Database transaction object.

BeginTransactionAsync(IsolationLevel, CancellationToken)

Starts new transaction asynchronously for current connection with specified isolation level.

Task<IAsyncDbTransaction> BeginTransactionAsync(IsolationLevel isolationLevel, CancellationToken cancellationToken)

Parameters

isolationLevel IsolationLevel

Transaction isolation level.

cancellationToken CancellationToken

Asynchronous operation cancellation token.

Returns

Task<IAsyncDbTransaction>

Database transaction object.

BeginTransactionAsync(CancellationToken)

Starts new transaction asynchronously for current connection with default isolation level.

Task<IAsyncDbTransaction> BeginTransactionAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Asynchronous operation cancellation token.

Returns

Task<IAsyncDbTransaction>

Database transaction object.

Close()

Closes the connection to the database. This is the preferred method of closing any open connection.

void Close()

Exceptions

DbException

The connection-level error that occurred while opening the connection.

CloseAsync()

Closes current connection asynchonously.

Task CloseAsync()

Returns

Task

Async operation task.

CreateCommand()

Creates and returns a DbCommand object associated with the current connection.

DbCommand CreateCommand()

Returns

DbCommand

A DbCommand object.

Open()

Opens a database connection with the settings specified by the ConnectionString.

void Open()

OpenAsync(CancellationToken)

This is the asynchronous version of Open(). Providers should override with an appropriate implementation. The cancellation token can optionally be honored.The default implementation invokes the synchronous Open() call and returns a completed task. The default implementation will return a cancelled task if passed an already cancelled cancellationToken. Exceptions thrown by Open will be communicated via the returned Task Exception property.Do not invoke other methods and properties of the DbConnection object until the returned Task is complete.

Task OpenAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The cancellation instruction.

Returns

Task

A task representing the asynchronous operation.

TryClone()

Returns cloned connection instance, if underlying provider supports cloning or null otherwise.

DbConnection? TryClone()

Returns

DbConnection