Table of Contents

Interface IDataContext

Namespace
LinqToDB
Assembly
linq2db.dll

Database connection abstraction interface.

public interface IDataContext : IConfigurationID, IDisposable, IAsyncDisposable
Inherited Members
Extension Methods

Properties

CloseAfterUse

Gets or sets flag to close context after query execution or leave it open.

bool CloseAfterUse { get; set; }

Property Value

bool

ConfigurationString

Gets initial value for database connection configuration name.

string? ConfigurationString { get; }

Property Value

string

ContextName

Provider identifier.

string ContextName { get; }

Property Value

string

CreateSqlBuilder

Gets SQL builder service factory method for current context data provider.

Func<ISqlBuilder> CreateSqlBuilder { get; }

Property Value

Func<ISqlBuilder>

DataReaderType

Gets data reader implementation type for current context data provider.

Type DataReaderType { get; }

Property Value

Type

GetSqlOptimizer

Gets SQL optimizer service factory method for current context data provider.

Func<DataOptions, ISqlOptimizer> GetSqlOptimizer { get; }

Property Value

Func<DataOptions, ISqlOptimizer>

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.

bool InlineParameters { get; set; }

Property Value

bool

MappingSchema

Gets mapping schema, used for current context.

MappingSchema MappingSchema { get; }

Property Value

MappingSchema

NextQueryHints

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

List<string> NextQueryHints { get; }

Property Value

List<string>

Options

Current DataContext LINQ options

DataOptions Options { get; }

Property Value

DataOptions

QueryHints

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

List<string> QueryHints { get; }

Property Value

List<string>

SqlProviderFlags

Gets SQL support flags for current context data provider.

SqlProviderFlags SqlProviderFlags { get; }

Property Value

SqlProviderFlags

SupportedTableOptions

Gets supported table options for current context data provider.

TableOptions SupportedTableOptions { get; }

Property Value

TableOptions

Methods

AddInterceptor(IInterceptor)

Adds interceptor instance to context.

void AddInterceptor(IInterceptor interceptor)

Parameters

interceptor IInterceptor

Interceptor.

AddMappingSchema(MappingSchema)

Adds mapping schema to current context.

void AddMappingSchema(MappingSchema mappingSchema)

Parameters

mappingSchema MappingSchema

Mapping schema to add.

Close()

Closes context connection and disposes underlying resources.

void Close()

CloseAsync()

Closes context connection and disposes underlying resources.

Task CloseAsync()

Returns

Task

GetQueryRunner(Query, IDataContext, int, IQueryExpressions, object?[]?, object?[]?)

Returns query runner service for current context.

IQueryRunner GetQueryRunner(Query query, IDataContext parametersContext, int queryNumber, IQueryExpressions expressions, object?[]? parameters, object?[]? preambles)

Parameters

query Query

Query batch object.

parametersContext IDataContext

Context instance which will be used for parameters evaluation.

queryNumber int

Index of query in query batch.

expressions IQueryExpressions

Query results mapping expressions.

parameters object[]

Query parameters.

preambles object[]

Query preambles.

Returns

IQueryRunner

Query runner service.

GetReaderExpression(DbDataReader, int, Expression, Type)

Returns column value reader expression.

Expression GetReaderExpression(DbDataReader reader, int idx, Expression readerExpression, Type toType)

Parameters

reader DbDataReader

Data reader instance.

idx int

Column index.

readerExpression Expression

Data reader accessor expression.

toType Type

Expected value type.

Returns

Expression

Column read expression.

IsDBNullAllowed(DbDataReader, int)

Returns true, of data reader column could contain DBNull value.

bool? IsDBNullAllowed(DbDataReader reader, int idx)

Parameters

reader DbDataReader

Data reader instance.

idx int

Column index.

Returns

bool?

true or null if column could contain DBNull.

RemoveInterceptor(IInterceptor)

Removes interceptor instance from context.

void RemoveInterceptor(IInterceptor interceptor)

Parameters

interceptor IInterceptor

Interceptor.

SetMappingSchema(MappingSchema)

Sets the current MappingSchema instance for the context.

Note: This method ultimately replaces the current mapping schema and should only be used if you need to create a new schema based on the existing one, or you are absolutely sure you know what you are doing.

void SetMappingSchema(MappingSchema mappingSchema)

Parameters

mappingSchema MappingSchema

Mapping schema to set.

UseMappingSchema(MappingSchema)

Sets new mapping schema for current data context.

Implements the Disposable pattern, which must be used to properly restore previous settings.

IDisposable? UseMappingSchema(MappingSchema mappingSchema)

Parameters

mappingSchema MappingSchema

Mapping schema to set.

Returns

IDisposable

UseOptions(Func<DataOptions, DataOptions>)

Sets new options for current data context.

Implements the Disposable pattern, which must be used to properly restore previous options.

IDisposable? UseOptions(Func<DataOptions, DataOptions> optionsSetter)

Parameters

optionsSetter Func<DataOptions, DataOptions>

Options setter function.

Returns

IDisposable

Returns disposable object, which could be used to restore previous options.

Remarks

For ConnectionOptions we update only mapping schema and connection interceptor. Connection string, configuration, data provider, etc. are not updatable.

Exceptions

ArgumentNullException