Class DataConnection
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
-
DataConnectionExtensions.QueryToArrayAsync<T>(DataConnection, T, string, CancellationToken, object?)DataConnectionExtensions.QueryToListAsync<T>(DataConnection, Func<DbDataReader, T>, string, object?)
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
DataOptionsOptions, 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
IDataProviderDatabase provider implementation to use with this connection.
connection
DbConnectionExisting 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
IDataProviderDatabase provider implementation to use with this connection.
connection
DbConnectionExisting database connection to use.
mappingSchema
MappingSchemaMapping 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
IDataProviderDatabase provider implementation to use with this connection.
connection
DbConnectionExisting database connection to use.
mappingSchema
MappingSchemaMapping 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
IDataProviderDatabase provider implementation to use with this connection.
connection
DbConnectionExisting database connection to use.
disposeConnection
boolIf 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
IDataProviderDatabase provider implementation to use with this connection.
connection
DbConnectionExisting database connection to use.
disposeConnection
boolIf 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
IDataProviderDatabase provider implementation to use with this connection.
connection
DbConnectionExisting 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
IDataProviderDatabase provider implementation to use with this connection.
transaction
DbTransactionExisting 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
IDataProviderDatabase provider implementation to use with this connection.
transaction
DbTransactionExisting database transaction to use.
mappingSchema
MappingSchemaMapping 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
IDataProviderDatabase provider implementation to use with this connection.
transaction
DbTransactionExisting database transaction to use.
mappingSchema
MappingSchemaMapping 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
IDataProviderDatabase provider implementation to use with this connection.
transaction
DbTransactionExisting 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
IDataProviderDatabase 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
IDataProviderDatabase provider implementation to use with this connection.
connectionFactory
Func<DataOptions, DbConnection>Database connection factory method.
mappingSchema
MappingSchemaMapping 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
IDataProviderDatabase provider implementation to use with this connection.
connectionFactory
Func<DataOptions, DbConnection>Database connection factory method.
mappingSchema
MappingSchemaMapping 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
IDataProviderDatabase 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
IDataProviderDatabase provider implementation to use with this connection.
connectionString
stringDatabase 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
IDataProviderDatabase provider implementation to use with this connection.
connectionString
stringDatabase connection string to use for connection with database.
mappingSchema
MappingSchemaMapping 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
IDataProviderDatabase provider implementation to use with this connection.
connectionString
stringDatabase connection string to use for connection with database.
mappingSchema
MappingSchemaMapping 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
IDataProviderDatabase provider implementation to use with this connection.
connectionString
stringDatabase 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
MappingSchemaMapping 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
MappingSchemaMapping 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
stringName 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
stringName of database connection configuration to use with this connection. In case of null, configuration from DefaultConfiguration property will be used.
mappingSchema
MappingSchemaMapping 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
stringName of database connection configuration to use with this connection. In case of null, configuration from DefaultConfiguration property will be used.
mappingSchema
MappingSchemaMapping 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
stringName 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
stringName of database provider to use with this connection. ProviderName class for list of providers.
connectionString
stringDatabase 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
stringName of database provider to use with this connection. ProviderName class for list of providers.
connectionString
stringDatabase connection string to use for connection with database.
mappingSchema
MappingSchemaMapping 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
stringName of database provider to use with this connection. ProviderName class for list of providers.
connectionString
stringDatabase connection string to use for connection with database.
mappingSchema
MappingSchemaMapping 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
stringName of database provider to use with this connection. ProviderName class for list of providers.
connectionString
stringDatabase 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).
TraceSwitchpublic static Action<string?, string?, TraceLevel> WriteTraceLine
Field Value
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
ConfigurationString
Database configuration name (connection string name).
public string? ConfigurationString { get; }
Property Value
Connection
Gets underlying database connection, used by current connection object.
public DbConnection Connection { get; }
Property Value
ConnectionString
Database connection string.
public string? ConnectionString { get; }
Property Value
DataProvider
Database provider implementation for specific database engine.
public IDataProvider DataProvider { get; }
Property Value
DefaultConfiguration
Gets or sets default connection configuration name. Used by DataConnection by default and could be set automatically from:
- 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
- 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
- See Also
DefaultOnTraceConnection
Gets or sets default trace handler.
public static Action<TraceInfo> DefaultOnTraceConnection { get; set; }
Property Value
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
Disposed
protected bool Disposed { get; }
Property Value
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
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
LastQuery
Contains text of last command, sent to database using current connection.
public string? LastQuery { get; }
Property Value
MappingSchema
Gets mapping schema, used for current connection.
public MappingSchema MappingSchema { get; }
Property Value
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
OnRemoveInterceptor
public Action<IInterceptor>? OnRemoveInterceptor { get; set; }
Property Value
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
Options
Current DataContext options
public DataOptions Options { get; }
Property Value
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
RetryPolicy
Retry policy for current connection.
public IRetryPolicy? RetryPolicy { get; set; }
Property Value
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.
public static TraceSwitch TraceSwitch { get; set; }
Property Value
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
Transaction
Gets current transaction, associated with connection.
public DbTransaction? Transaction { get; }
Property Value
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
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
stringConnection configuration name.
connectionString
stringConnection string.
dataProvider
IDataProviderDatabase 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
IDataProviderDatabase provider implementation.
AddDataProvider(string, IDataProvider)
Registers database provider implementation by provided unique name.
public static void AddDataProvider(string providerName, IDataProvider dataProvider)
Parameters
providerName
stringProvider name, to which provider implementation will be mapped.
dataProvider
IDataProviderDatabase provider implementation.
AddInterceptor(IInterceptor)
Adds interceptor instance to context.
public void AddInterceptor(IInterceptor interceptor)
Parameters
interceptor
IInterceptorInterceptor.
AddMappingSchema(MappingSchema)
Adds additional mapping schema to current connection.
public DataConnection AddMappingSchema(MappingSchema mappingSchema)
Parameters
mappingSchema
MappingSchemaMapping 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
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
IsolationLevelTransaction 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
IsolationLevelTransaction isolation level.
cancellationToken
CancellationTokenAsynchronous 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
CancellationTokenAsynchronous 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
CancellationTokenAsynchronous 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
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
CancellationTokenAsynchronous operation cancellation token.
Returns
- Task
Async operation task.
ExecuteNonQuery(DbCommand)
protected virtual int ExecuteNonQuery(DbCommand command)
Parameters
command
DbCommand
Returns
ExecuteNonQueryAsync(CancellationToken)
protected virtual Task<int> ExecuteNonQueryAsync(CancellationToken cancellationToken)
Parameters
cancellationToken
CancellationToken
Returns
ExecuteReader(CommandBehavior)
protected virtual DataReaderWrapper ExecuteReader(CommandBehavior commandBehavior)
Parameters
commandBehavior
CommandBehavior
Returns
ExecuteReaderAsync(CommandBehavior, CancellationToken)
protected virtual Task<DataReaderWrapper> ExecuteReaderAsync(CommandBehavior commandBehavior, CancellationToken cancellationToken)
Parameters
commandBehavior
CommandBehaviorcancellationToken
CancellationToken
Returns
ExecuteScalar(DbCommand)
protected virtual object? ExecuteScalar(DbCommand command)
Parameters
command
DbCommand
Returns
ExecuteScalarAsync(CancellationToken)
protected virtual Task<object?> ExecuteScalarAsync(CancellationToken cancellationToken)
Parameters
cancellationToken
CancellationToken
Returns
GetConnectionString(string)
Returns connection string for specified connection name.
public static string GetConnectionString(string configurationString)
Parameters
configurationString
stringConnection 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
stringConnection 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
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
stringProvider name.
configurationString
stringConnection configuration name.
connectionString
stringConnection 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
SqlStatementcontext
EvaluationContext
Returns
RemoveInterceptor(IInterceptor)
Removes interceptor instance from context.
public void RemoveInterceptor(IInterceptor interceptor)
Parameters
interceptor
IInterceptorInterceptor.
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
CancellationTokenAsynchronous 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
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
DataConnectiontraceOperation
TraceOperationcommandText
Func<TContext, string>context
TContextaction
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
DataConnectiontraceOperation
TraceOperationcommandText
Func<TContext, string>context
TContextaction
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
stringConfiguration.
Returns
- string
Connection string or NULL.
TurnTraceSwitchOn(TraceLevel)
Sets tracing level for data connections.
public static void TurnTraceSwitchOn(TraceLevel traceLevel = TraceLevel.Info)
Parameters
traceLevel
TraceLevelConnection tracing level.
Remarks
Use TraceSwitchConnection when possible, configured via UseTraceLevel(DataOptions, TraceLevel).