Table of Contents

Class DataConnection

Namespace
LinqToDB.Data
Assembly
linq2db.dll

Implements persistent database connection abstraction over different database engines. Could be initialized using connection string name or connection string, or attached to existing connection or transaction.

public class DataConnection : IDataContext, IConfigurationID, IDisposable, IAsyncDisposable, ICloneable, IInterceptable<ICommandInterceptor>, IInterceptable<IConnectionInterceptor>, IInterceptable<IDataContextInterceptor>, IInterceptable<IEntityServiceInterceptor>, IInterceptable<IUnwrapDataObjectInterceptor>, IInterceptable
Inheritance
DataConnection
Implements
Extension Methods

Constructors

DataConnection()

Creates database connection object that uses default connection configuration from DefaultConfiguration property.

public DataConnection()

DataConnection(DataOptions)

Creates database connection object that uses a DataOptions to configure the connection.

public DataConnection(DataOptions options)

Parameters

options DataOptions

Options, setup ahead of time.

DataConnection(IDataProvider, DbConnection)

Creates database connection object that uses specified database provider and connection.

public DataConnection(IDataProvider dataProvider, DbConnection connection)

Parameters

dataProvider IDataProvider

Database provider implementation to use with this connection.

connection DbConnection

Existing database connection to use.

Remarks

connection would not be disposed.

DataConnection(IDataProvider, DbConnection, MappingSchema)

Creates database connection object that uses specified database provider, connection and mapping schema.

public DataConnection(IDataProvider dataProvider, DbConnection connection, MappingSchema mappingSchema)

Parameters

dataProvider IDataProvider

Database provider implementation to use with this connection.

connection DbConnection

Existing database connection to use.

mappingSchema MappingSchema

Mapping schema to use with this connection.

DataConnection(IDataProvider, DbConnection, MappingSchema, Func<DataOptions, DataOptions>)

Creates database connection object that uses specified database provider, connection and mapping schema.

public DataConnection(IDataProvider dataProvider, DbConnection connection, MappingSchema mappingSchema, Func<DataOptions, DataOptions> optionsSetter)

Parameters

dataProvider IDataProvider

Database provider implementation to use with this connection.

connection DbConnection

Existing database connection to use.

mappingSchema MappingSchema

Mapping schema to use with this connection.

optionsSetter Func<DataOptions, DataOptions>

DataConnection(IDataProvider, DbConnection, bool)

Creates database connection object that uses specified database provider and connection.

public DataConnection(IDataProvider dataProvider, DbConnection connection, bool disposeConnection)

Parameters

dataProvider IDataProvider

Database provider implementation to use with this connection.

connection DbConnection

Existing database connection to use.

disposeConnection bool

If true connection would be disposed on DataConnection disposing.

DataConnection(IDataProvider, DbConnection, bool, Func<DataOptions, DataOptions>)

Creates database connection object that uses specified database provider and connection.

public DataConnection(IDataProvider dataProvider, DbConnection connection, bool disposeConnection, Func<DataOptions, DataOptions> optionsSetter)

Parameters

dataProvider IDataProvider

Database provider implementation to use with this connection.

connection DbConnection

Existing database connection to use.

disposeConnection bool

If true connection would be disposed on DataConnection disposing.

optionsSetter Func<DataOptions, DataOptions>

DataConnection(IDataProvider, DbConnection, Func<DataOptions, DataOptions>)

Creates database connection object that uses specified database provider and connection.

public DataConnection(IDataProvider dataProvider, DbConnection connection, Func<DataOptions, DataOptions> optionsSetter)

Parameters

dataProvider IDataProvider

Database provider implementation to use with this connection.

connection DbConnection

Existing database connection to use.

optionsSetter Func<DataOptions, DataOptions>

Remarks

connection would not be disposed.

DataConnection(IDataProvider, DbTransaction)

Creates database connection object that uses specified database provider and transaction.

public DataConnection(IDataProvider dataProvider, DbTransaction transaction)

Parameters

dataProvider IDataProvider

Database provider implementation to use with this connection.

transaction DbTransaction

Existing database transaction to use.

DataConnection(IDataProvider, DbTransaction, MappingSchema)

Creates database connection object that uses specified database provider, transaction and mapping schema.

public DataConnection(IDataProvider dataProvider, DbTransaction transaction, MappingSchema mappingSchema)

Parameters

dataProvider IDataProvider

Database provider implementation to use with this connection.

transaction DbTransaction

Existing database transaction to use.

mappingSchema MappingSchema

Mapping schema to use with this connection.

DataConnection(IDataProvider, DbTransaction, MappingSchema, Func<DataOptions, DataOptions>)

Creates database connection object that uses specified database provider, transaction and mapping schema.

public DataConnection(IDataProvider dataProvider, DbTransaction transaction, MappingSchema mappingSchema, Func<DataOptions, DataOptions> optionsSetter)

Parameters

dataProvider IDataProvider

Database provider implementation to use with this connection.

transaction DbTransaction

Existing database transaction to use.

mappingSchema MappingSchema

Mapping schema to use with this connection.

optionsSetter Func<DataOptions, DataOptions>

DataConnection(IDataProvider, DbTransaction, Func<DataOptions, DataOptions>)

Creates database connection object that uses specified database provider and transaction.

public DataConnection(IDataProvider dataProvider, DbTransaction transaction, Func<DataOptions, DataOptions> optionsSetter)

Parameters

dataProvider IDataProvider

Database provider implementation to use with this connection.

transaction DbTransaction

Existing database transaction to use.

optionsSetter Func<DataOptions, DataOptions>

DataConnection(IDataProvider, Func<DataOptions, DbConnection>)

Creates database connection object that uses specified database provider and connection factory.

public DataConnection(IDataProvider dataProvider, Func<DataOptions, DbConnection> connectionFactory)

Parameters

dataProvider IDataProvider

Database provider implementation to use with this connection.

connectionFactory Func<DataOptions, DbConnection>

Database connection factory method.

DataConnection(IDataProvider, Func<DataOptions, DbConnection>, MappingSchema)

Creates database connection object that uses specified database provider, connection factory and mapping schema.

public DataConnection(IDataProvider dataProvider, Func<DataOptions, DbConnection> connectionFactory, MappingSchema mappingSchema)

Parameters

dataProvider IDataProvider

Database provider implementation to use with this connection.

connectionFactory Func<DataOptions, DbConnection>

Database connection factory method.

mappingSchema MappingSchema

Mapping schema to use with this connection.

DataConnection(IDataProvider, Func<DataOptions, DbConnection>, MappingSchema, Func<DataOptions, DataOptions>)

Creates database connection object that uses specified database provider, connection factory and mapping schema.

public DataConnection(IDataProvider dataProvider, Func<DataOptions, DbConnection> connectionFactory, MappingSchema mappingSchema, Func<DataOptions, DataOptions> optionsSetter)

Parameters

dataProvider IDataProvider

Database provider implementation to use with this connection.

connectionFactory Func<DataOptions, DbConnection>

Database connection factory method.

mappingSchema MappingSchema

Mapping schema to use with this connection.

optionsSetter Func<DataOptions, DataOptions>

DataConnection(IDataProvider, Func<DataOptions, DbConnection>, Func<DataOptions, DataOptions>)

Creates database connection object that uses specified database provider and connection factory.

public DataConnection(IDataProvider dataProvider, Func<DataOptions, DbConnection> connectionFactory, Func<DataOptions, DataOptions> optionsSetter)

Parameters

dataProvider IDataProvider

Database provider implementation to use with this connection.

connectionFactory Func<DataOptions, DbConnection>

Database connection factory method.

optionsSetter Func<DataOptions, DataOptions>

DataConnection(IDataProvider, string)

Creates database connection object that uses specified database provider and connection string.

public DataConnection(IDataProvider dataProvider, string connectionString)

Parameters

dataProvider IDataProvider

Database provider implementation to use with this connection.

connectionString string

Database connection string to use for connection with database.

DataConnection(IDataProvider, string, MappingSchema)

Creates database connection object that uses specified database provider, connection string and mapping schema.

public DataConnection(IDataProvider dataProvider, string connectionString, MappingSchema mappingSchema)

Parameters

dataProvider IDataProvider

Database provider implementation to use with this connection.

connectionString string

Database connection string to use for connection with database.

mappingSchema MappingSchema

Mapping schema to use with this connection.

DataConnection(IDataProvider, string, MappingSchema, Func<DataOptions, DataOptions>)

Creates database connection object that uses specified database provider, connection string and mapping schema.

public DataConnection(IDataProvider dataProvider, string connectionString, MappingSchema mappingSchema, Func<DataOptions, DataOptions> optionsSetter)

Parameters

dataProvider IDataProvider

Database provider implementation to use with this connection.

connectionString string

Database connection string to use for connection with database.

mappingSchema MappingSchema

Mapping schema to use with this connection.

optionsSetter Func<DataOptions, DataOptions>

DataConnection(IDataProvider, string, Func<DataOptions, DataOptions>)

Creates database connection object that uses specified database provider and connection string.

public DataConnection(IDataProvider dataProvider, string connectionString, Func<DataOptions, DataOptions> optionsSetter)

Parameters

dataProvider IDataProvider

Database provider implementation to use with this connection.

connectionString string

Database connection string to use for connection with database.

optionsSetter Func<DataOptions, DataOptions>

DataConnection(MappingSchema)

Creates database connection object that uses default connection configuration from DefaultConfiguration property and provided mapping schema.

public DataConnection(MappingSchema mappingSchema)

Parameters

mappingSchema MappingSchema

Mapping schema to use with this connection.

DataConnection(MappingSchema, Func<DataOptions, DataOptions>)

Creates database connection object that uses default connection configuration from DefaultConfiguration property and provided mapping schema.

public DataConnection(MappingSchema mappingSchema, Func<DataOptions, DataOptions> optionsSetter)

Parameters

mappingSchema MappingSchema

Mapping schema to use with this connection.

optionsSetter Func<DataOptions, DataOptions>

DataConnection(Func<DataOptions, DataOptions>)

Creates database connection object that uses default connection configuration from DefaultConfiguration property.

public DataConnection(Func<DataOptions, DataOptions> optionsSetter)

Parameters

optionsSetter Func<DataOptions, DataOptions>

DataConnection(string?)

Creates database connection object that uses provided connection configuration.

public DataConnection(string? configurationString)

Parameters

configurationString string

Name of database connection configuration to use with this connection. In case of null, configuration from DefaultConfiguration property will be used.

DataConnection(string?, MappingSchema)

Creates database connection object that uses provided connection configuration and mapping schema.

public DataConnection(string? configurationString, MappingSchema mappingSchema)

Parameters

configurationString string

Name of database connection configuration to use with this connection. In case of null, configuration from DefaultConfiguration property will be used.

mappingSchema MappingSchema

Mapping schema to use with this connection.

DataConnection(string?, MappingSchema, Func<DataOptions, DataOptions>)

Creates database connection object that uses provided connection configuration and mapping schema.

public DataConnection(string? configurationString, MappingSchema mappingSchema, Func<DataOptions, DataOptions> optionsSetter)

Parameters

configurationString string

Name of database connection configuration to use with this connection. In case of null, configuration from DefaultConfiguration property will be used.

mappingSchema MappingSchema

Mapping schema to use with this connection.

optionsSetter Func<DataOptions, DataOptions>

DataConnection(string?, Func<DataOptions, DataOptions>)

Creates database connection object that uses provided connection configuration.

public DataConnection(string? configurationString, Func<DataOptions, DataOptions> optionsSetter)

Parameters

configurationString string

Name of database connection configuration to use with this connection. In case of null, configuration from DefaultConfiguration property will be used.

optionsSetter Func<DataOptions, DataOptions>

DataConnection(string, string)

Creates database connection object that uses specified database provider and connection string.

public DataConnection(string providerName, string connectionString)

Parameters

providerName string

Name of database provider to use with this connection. ProviderName class for list of providers.

connectionString string

Database connection string to use for connection with database.

DataConnection(string, string, MappingSchema)

Creates database connection object that uses specified database provider, connection string and mapping schema.

public DataConnection(string providerName, string connectionString, MappingSchema mappingSchema)

Parameters

providerName string

Name of database provider to use with this connection. ProviderName class for list of providers.

connectionString string

Database connection string to use for connection with database.

mappingSchema MappingSchema

Mapping schema to use with this connection.

DataConnection(string, string, MappingSchema, Func<DataOptions, DataOptions>)

Creates database connection object that uses specified database provider, connection string and mapping schema.

public DataConnection(string providerName, string connectionString, MappingSchema mappingSchema, Func<DataOptions, DataOptions> optionsSetter)

Parameters

providerName string

Name of database provider to use with this connection. ProviderName class for list of providers.

connectionString string

Database connection string to use for connection with database.

mappingSchema MappingSchema

Mapping schema to use with this connection.

optionsSetter Func<DataOptions, DataOptions>

DataConnection(string, string, Func<DataOptions, DataOptions>)

Creates database connection object that uses specified database provider and connection string.

public DataConnection(string providerName, string connectionString, Func<DataOptions, DataOptions> optionsSetter)

Parameters

providerName string

Name of database provider to use with this connection. ProviderName class for list of providers.

connectionString string

Database connection string to use for connection with database.

optionsSetter Func<DataOptions, DataOptions>

Fields

WriteTraceLine

Trace function. By Default use Debug class for logging, but could be replaced to log e.g. to your log file. will be ignored if UseTraceWith(DataOptions, Action<string?, string?, TraceLevel>) is called on builder

First parameter contains trace message.

Second parameter contains trace message category (DisplayName).

Third parameter contains trace level for message (TraceLevel).

TraceSwitchShould only not use to write trace lines, only use WriteTraceLineConnection.
public static Action<string?, string?, TraceLevel> WriteTraceLine

Field Value

Action<string, string, TraceLevel>

Properties

CommandTimeout

Gets or sets command execution timeout in seconds. Negative timeout value means that default timeout will be used. 0 timeout value corresponds to infinite timeout. By default timeout is not set and default value for current provider used.

public int CommandTimeout { get; set; }

Property Value

int

ConfigurationString

Database configuration name (connection string name).

public string? ConfigurationString { get; }

Property Value

string

Connection

Gets underlying database connection, used by current connection object.

public DbConnection Connection { get; }

Property Value

DbConnection

ConnectionString

Database connection string.

public string? ConnectionString { get; }

Property Value

string

DataProvider

Database provider implementation for specific database engine.

public IDataProvider DataProvider { get; }

Property Value

IDataProvider

DefaultConfiguration

Gets or sets default connection configuration name. Used by DataConnection by default and could be set automatically from:

- DefaultConfiguration;

- first non-global connection string name from ConnectionStrings;

- first non-global connection string name passed to SetConnectionStrings(IEnumerable<IConnectionStringSettings>) method.

public static string? DefaultConfiguration { get; set; }

Property Value

string
See Also

DefaultDataProvider

Gets or sets name of default data provider, used by new connection if user didn't specified provider explicitly in constructor or in connection options. Initialized with value from DefaultSettings.DefaultDataProvider.

public static string? DefaultDataProvider { get; set; }

Property Value

string
See Also

DefaultOnTraceConnection

Gets or sets default trace handler.

public static Action<TraceInfo> DefaultOnTraceConnection { get; set; }

Property Value

Action<TraceInfo>

DefaultSettings

Gets or sets default connection settings. By default contains settings from linq2db configuration section from configuration file (not supported by .Net Core). ILinqToDBSettings

public static ILinqToDBSettings? DefaultSettings { get; set; }

Property Value

ILinqToDBSettings

Disposed

protected bool Disposed { get; }

Property Value

bool

InlineParameters

Gets or sets option to force inline parameter values as literals into command text. If parameter inlining not supported for specific value type, it will be used as parameter.

public bool InlineParameters { get; set; }

Property Value

bool

IsMarsEnabled

Gets or sets status of Multiple Active Result Sets (MARS) feature. This feature available only for SQL Azure and SQL Server 2005+.

public bool IsMarsEnabled { get; set; }

Property Value

bool

LastQuery

Contains text of last command, sent to database using current connection.

public string? LastQuery { get; }

Property Value

string

MappingSchema

Gets mapping schema, used for current connection.

public MappingSchema MappingSchema { get; }

Property Value

MappingSchema

NextQueryHints

Gets list of query hints (writable collection), that will be used only for next query, executed through current connection.

public List<string> NextQueryHints { get; }

Property Value

List<string>

OnRemoveInterceptor

public Action<IInterceptor>? OnRemoveInterceptor { get; set; }

Property Value

Action<IInterceptor>

OnTraceConnection

Gets or sets trace handler, used for current connection instance. Configured on the connection builder using UseTracing(DataOptions, Action<TraceInfo>). defaults to WriteTraceLineConnection calls.

public Action<TraceInfo> OnTraceConnection { get; set; }

Property Value

Action<TraceInfo>

Options

Current DataContext options

public DataOptions Options { get; }

Property Value

DataOptions

QueryHints

Gets list of query hints (writable collection), that will be used for all queries, executed through current connection.

public List<string> QueryHints { get; }

Property Value

List<string>

RetryPolicy

Retry policy for current connection.

public IRetryPolicy? RetryPolicy { get; set; }

Property Value

IRetryPolicy

ThrowOnDisposed

public bool? ThrowOnDisposed { get; set; }

Property Value

bool?

TraceSwitch

Gets or sets global data connection trace options. Used for all new connections unless UseTraceLevel(DataOptions, TraceLevel) is called on builder. defaults to off unless library was built in debug mode. Should only be used when TraceSwitchConnection can not be used!

public static TraceSwitch TraceSwitch { get; set; }

Property Value

TraceSwitch

TraceSwitchConnection

gets or sets the trace switch, this is used by some methods to determine if OnTraceConnection should be called. defaults to TraceSwitch used for current connection instance.

public TraceSwitch TraceSwitchConnection { get; set; }

Property Value

TraceSwitch

Transaction

Gets current transaction, associated with connection.

public DbTransaction? Transaction { get; }

Property Value

DbTransaction

WriteTraceLineConnection

Gets the delegate to write logging messages for this connection. Defaults to WriteTraceLine. Used for the current instance.

public Action<string?, string?, TraceLevel> WriteTraceLineConnection { get; protected set; }

Property Value

Action<string, string, TraceLevel>

Methods

AddConfiguration(string, string, IDataProvider?)

Register connection configuration with specified connection string and database provider implementation.

public static void AddConfiguration(string configuration, string connectionString, IDataProvider? dataProvider = null)

Parameters

configuration string

Connection configuration name.

connectionString string

Connection string.

dataProvider IDataProvider

Database provider. If not specified, will use provider, registered using configuration value.

AddDataProvider(IDataProvider)

Registers database provider implementation using Name name.

public static void AddDataProvider(IDataProvider dataProvider)

Parameters

dataProvider IDataProvider

Database provider implementation.

AddDataProvider(string, IDataProvider)

Registers database provider implementation by provided unique name.

public static void AddDataProvider(string providerName, IDataProvider dataProvider)

Parameters

providerName string

Provider name, to which provider implementation will be mapped.

dataProvider IDataProvider

Database provider implementation.

AddInterceptor(IInterceptor)

Adds interceptor instance to context.

public void AddInterceptor(IInterceptor interceptor)

Parameters

interceptor IInterceptor

Interceptor.

AddMappingSchema(MappingSchema)

Adds additional mapping schema to current connection.

public DataConnection AddMappingSchema(MappingSchema mappingSchema)

Parameters

mappingSchema MappingSchema

Mapping schema.

Returns

DataConnection

Current connection object.

Remarks

DataConnection will share MappingSchema instances that were created by combining same mapping schemas.

AddOrSetConfiguration(string, string, string)

public static void AddOrSetConfiguration(string configuration, string connectionString, string dataProvider)

Parameters

configuration string
connectionString string
dataProvider string

AddProviderDetector(Func<ConnectionOptions, IDataProvider?>)

Registers database provider factory method. Factory accepts connection string settings and connection string. Could return null, if cannot create provider instance using provided options.

public static void AddProviderDetector(Func<ConnectionOptions, IDataProvider?> providerDetector)

Parameters

providerDetector Func<ConnectionOptions, IDataProvider>

Factory method delegate.

BeginTransaction()

Starts new transaction for current connection with default isolation level. If connection already has transaction, it will be rolled back.

public virtual DataConnectionTransaction BeginTransaction()

Returns

DataConnectionTransaction

Database transaction object.

BeginTransaction(IsolationLevel)

Starts new transaction for current connection with specified isolation level. If connection already have transaction, it will be rolled back.

public virtual DataConnectionTransaction BeginTransaction(IsolationLevel isolationLevel)

Parameters

isolationLevel IsolationLevel

Transaction isolation level.

Returns

DataConnectionTransaction

Database transaction object.

BeginTransactionAsync(IsolationLevel, CancellationToken)

Starts new transaction asynchronously for current connection with specified isolation level. If connection already have transaction, it will be rolled back.

public virtual Task<DataConnectionTransaction> BeginTransactionAsync(IsolationLevel isolationLevel, CancellationToken cancellationToken = default)

Parameters

isolationLevel IsolationLevel

Transaction isolation level.

cancellationToken CancellationToken

Asynchronous operation cancellation token.

Returns

Task<DataConnectionTransaction>

Database transaction object.

BeginTransactionAsync(CancellationToken)

Starts new transaction asynchronously for current connection with default isolation level. If connection already has transaction, it will be rolled back.

public virtual Task<DataConnectionTransaction> BeginTransactionAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Asynchronous operation cancellation token.

Returns

Task<DataConnectionTransaction>

Database transaction object.

CheckAndThrowOnDisposed()

protected void CheckAndThrowOnDisposed()

ClearObjectReaderCache()

Removes cached data mappers.

public static void ClearObjectReaderCache()

Clone()

Clones current connection.

public object Clone()

Returns

object

Cloned connection.

Close()

Closes and dispose associated underlying database transaction/connection.

public virtual void Close()

CloseAsync()

Closes and dispose associated underlying database transaction/connection asynchronously.

public virtual Task CloseAsync()

Returns

Task

Asynchronous operation completion task.

CommitTransaction()

Commits transaction (if any), associated with connection.

public virtual void CommitTransaction()

CommitTransactionAsync(CancellationToken)

Commits started (if any) transaction, associated with connection. If underlying provider doesn't support asynchronous commit, it will be performed synchronously.

public virtual Task CommitTransactionAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Asynchronous operation cancellation token.

Returns

Task

Asynchronous operation completion task.

CreateCommand()

This is internal API and is not intended for use by Linq To DB applications.

public DbCommand CreateCommand()

Returns

DbCommand

Dispose()

Disposes connection.

public void Dispose()

DisposeAsync()

Disposes connection asynchronously.

public Task DisposeAsync()

Returns

Task

Asynchronous operation completion task.

DisposeCommand()

This is internal API and is not intended for use by Linq To DB applications.

public void DisposeCommand()

DisposeTransaction()

Disposes transaction (if any), associated with connection.

public virtual void DisposeTransaction()

DisposeTransactionAsync()

Dispose started (if any) transaction, associated with connection. If underlying provider doesn't support asynchonous disposal, it will be performed synchonously.

public virtual Task DisposeTransactionAsync()

Returns

Task

Asynchronous operation completion task.

EnsureConnectionAsync(CancellationToken)

Ensure that database connection opened. If opened connection missing, it will be opened asynchronously.

public Task EnsureConnectionAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Asynchronous operation cancellation token.

Returns

Task

Async operation task.

ExecuteNonQuery(DbCommand)

protected virtual int ExecuteNonQuery(DbCommand command)

Parameters

command DbCommand

Returns

int

ExecuteNonQueryAsync(CancellationToken)

protected virtual Task<int> ExecuteNonQueryAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task<int>

ExecuteReader(CommandBehavior)

protected virtual DataReaderWrapper ExecuteReader(CommandBehavior commandBehavior)

Parameters

commandBehavior CommandBehavior

Returns

DataReaderWrapper

ExecuteReaderAsync(CommandBehavior, CancellationToken)

protected virtual Task<DataReaderWrapper> ExecuteReaderAsync(CommandBehavior commandBehavior, CancellationToken cancellationToken)

Parameters

commandBehavior CommandBehavior
cancellationToken CancellationToken

Returns

Task<DataReaderWrapper>

ExecuteScalar(DbCommand)

protected virtual object? ExecuteScalar(DbCommand command)

Parameters

command DbCommand

Returns

object

ExecuteScalarAsync(CancellationToken)

protected virtual Task<object?> ExecuteScalarAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task<object>

GetConnectionString(string)

Returns connection string for specified connection name.

public static string GetConnectionString(string configurationString)

Parameters

configurationString string

Connection name.

Returns

string

Connection string.

GetDataProvider(string)

Returns database provider implementation, associated with provided connection configuration name.

public static IDataProvider GetDataProvider(string configurationString)

Parameters

configurationString string

Connection configuration name.

Returns

IDataProvider

Database provider.

GetDataProvider(string, string)

Returns database provider associated with provider name and connection string.

public static IDataProvider? GetDataProvider(string providerName, string connectionString)

Parameters

providerName string

Provider name.

connectionString string

Connection string.

Returns

IDataProvider

Database provider.

GetDataProvider(string, string, string)

Returns database provider associated with provider name, configuration and connection string.

public static IDataProvider? GetDataProvider(string providerName, string configurationString, string connectionString)

Parameters

providerName string

Provider name.

configurationString string

Connection configuration name.

connectionString string

Connection string.

Returns

IDataProvider

Database provider.

GetRegisteredProviders()

Returns registered database providers.

public static IReadOnlyDictionary<string, IDataProvider> GetRegisteredProviders()

Returns

IReadOnlyDictionary<string, IDataProvider>

Returns registered providers collection.

InsertProviderDetector(Func<ConnectionOptions, IDataProvider?>)

Registers database provider factory method. Factory accepts connection string settings and connection string. Could return null, if cannot create provider instance using provided options.

public static void InsertProviderDetector(Func<ConnectionOptions, IDataProvider?> providerDetector)

Parameters

providerDetector Func<ConnectionOptions, IDataProvider>

Factory method delegate.

ProcessQuery(SqlStatement, EvaluationContext)

protected virtual SqlStatement ProcessQuery(SqlStatement statement, EvaluationContext context)

Parameters

statement SqlStatement
context EvaluationContext

Returns

SqlStatement

RemoveInterceptor(IInterceptor)

Removes interceptor instance from context.

public void RemoveInterceptor(IInterceptor interceptor)

Parameters

interceptor IInterceptor

Interceptor.

RollbackTransaction()

Rollbacks transaction (if any), associated with connection.

public virtual void RollbackTransaction()

RollbackTransactionAsync(CancellationToken)

Rollbacks started (if any) transaction, associated with connection. If underlying provider doesn't support asynchonous commit, it will be performed synchonously.

public virtual Task RollbackTransactionAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Asynchronous operation cancellation token.

Returns

Task

Asynchronous operation completion task.

SetConnectionString(string, string)

Sets connection string for specified connection name.

public static void SetConnectionString(string configuration, string connectionString)

Parameters

configuration string

Connection name.

connectionString string

Connection string.

SetConnectionStrings(IEnumerable<IConnectionStringSettings>)

Register connection strings for use by data connection class.

public static void SetConnectionStrings(IEnumerable<IConnectionStringSettings> connectionStrings)

Parameters

connectionStrings IEnumerable<IConnectionStringSettings>

Collection of connection string configurations.

TraceActionAsync<TContext, TResult>(DataConnection, TraceOperation, Func<TContext, string?>?, TContext, Func<DataConnection, TContext, CancellationToken, Task<TResult>>, CancellationToken)

protected static Task<TResult> TraceActionAsync<TContext, TResult>(DataConnection dataConnection, TraceOperation traceOperation, Func<TContext, string?>? commandText, TContext context, Func<DataConnection, TContext, CancellationToken, Task<TResult>> action, CancellationToken cancellationToken)

Parameters

dataConnection DataConnection
traceOperation TraceOperation
commandText Func<TContext, string>
context TContext
action Func<DataConnection, TContext, CancellationToken, Task<TResult>>
cancellationToken CancellationToken

Returns

Task<TResult>

Type Parameters

TContext
TResult

TraceAction<TContext, TResult>(DataConnection, TraceOperation, Func<TContext, string?>?, TContext, Func<DataConnection, TContext, TResult>)

protected static TResult TraceAction<TContext, TResult>(DataConnection dataConnection, TraceOperation traceOperation, Func<TContext, string?>? commandText, TContext context, Func<DataConnection, TContext, TResult> action)

Parameters

dataConnection DataConnection
traceOperation TraceOperation
commandText Func<TContext, string>
context TContext
action Func<DataConnection, TContext, TResult>

Returns

TResult

Type Parameters

TContext
TResult

TryGetConnectionString(string?)

Returns connection string for specified configuration name or NULL.

public static string? TryGetConnectionString(string? configurationString)

Parameters

configurationString string

Configuration.

Returns

string

Connection string or NULL.

TurnTraceSwitchOn(TraceLevel)

Sets tracing level for data connections.

public static void TurnTraceSwitchOn(TraceLevel traceLevel = TraceLevel.Info)

Parameters

traceLevel TraceLevel

Connection tracing level.

Remarks