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

CreateSqlProvider

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

Func<ISqlBuilder> CreateSqlProvider { 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

UnwrapDataObjectInterceptor

IUnwrapDataObjectInterceptor? UnwrapDataObjectInterceptor { get; }

Property Value

IUnwrapDataObjectInterceptor

Methods

AddInterceptor(IInterceptor)

Adds interceptor instance to context.

void AddInterceptor(IInterceptor interceptor)

Parameters

interceptor IInterceptor

Interceptor.

Clone(bool)

Clones current context.

IDataContext Clone(bool forNestedQuery)

Parameters

forNestedQuery bool

Returns

IDataContext

Cloned context.

Close()

Closes context connection and disposes underlying resources.

void Close()

CloseAsync()

Closes context connection and disposes underlying resources.

Task CloseAsync()

Returns

Task

GetQueryRunner(Query, int, Expression, object?[]?, object?[]?)

Returns query runner service for current context.

IQueryRunner GetQueryRunner(Query query, int queryNumber, Expression expression, object?[]? parameters, object?[]? preambles)

Parameters

query Query

Query batch object.

queryNumber int

Index of query in query batch.

expression Expression

Query results mapping expression.

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.