Interface IDataContext
- Namespace
- LinqToDB
- Assembly
- linq2db.dll
Database connection abstraction interface.
public interface IDataContext : IConfigurationID, IDisposable, IAsyncDisposable
- Inherited Members
- Extension Methods
-
DataContextExtensions.QueryAsync<T>(IDataContext, string, CancellationToken, params DataParameter[])DataExtensions.InsertOrReplace<T>(IDataContext, T, string?, string?, string?, string?, TableOptions)
Properties
CloseAfterUse
Gets or sets flag to close context after query execution or leave it open.
bool CloseAfterUse { get; set; }
Property Value
ConfigurationString
Gets initial value for database connection configuration name.
string? ConfigurationString { get; }
Property Value
ContextName
Provider identifier.
string ContextName { get; }
Property Value
CreateSqlBuilder
Gets SQL builder service factory method for current context data provider.
Func<ISqlBuilder> CreateSqlBuilder { get; }
Property Value
DataReaderType
Gets data reader implementation type for current context data provider.
Type DataReaderType { get; }
Property Value
GetSqlOptimizer
Gets SQL optimizer service factory method for current context data provider.
Func<DataOptions, ISqlOptimizer> GetSqlOptimizer { 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.
bool InlineParameters { get; set; }
Property Value
MappingSchema
Gets mapping schema, used for current context.
MappingSchema MappingSchema { get; }
Property Value
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
Options
Current DataContext LINQ options
DataOptions Options { get; }
Property Value
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
SqlProviderFlags
Gets SQL support flags for current context data provider.
SqlProviderFlags SqlProviderFlags { get; }
Property Value
SupportedTableOptions
Gets supported table options for current context data provider.
TableOptions SupportedTableOptions { get; }
Property Value
Methods
AddInterceptor(IInterceptor)
Adds interceptor instance to context.
void AddInterceptor(IInterceptor interceptor)
Parameters
interceptorIInterceptorInterceptor.
AddMappingSchema(MappingSchema)
Adds mapping schema to current context.
void AddMappingSchema(MappingSchema mappingSchema)
Parameters
mappingSchemaMappingSchemaMapping schema to add.
Close()
Closes context connection and disposes underlying resources.
void Close()
CloseAsync()
Closes context connection and disposes underlying resources.
Task CloseAsync()
Returns
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
queryQueryQuery batch object.
parametersContextIDataContextContext instance which will be used for parameters evaluation.
queryNumberintIndex of query in query batch.
expressionsIQueryExpressionsQuery results mapping expressions.
parametersobject[]Query parameters.
preamblesobject[]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
readerDbDataReaderData reader instance.
idxintColumn index.
readerExpressionExpressionData reader accessor expression.
toTypeTypeExpected 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
readerDbDataReaderData reader instance.
idxintColumn index.
Returns
RemoveInterceptor(IInterceptor)
Removes interceptor instance from context.
void RemoveInterceptor(IInterceptor interceptor)
Parameters
interceptorIInterceptorInterceptor.
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
mappingSchemaMappingSchemaMapping 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
mappingSchemaMappingSchemaMapping schema to set.
Returns
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
optionsSetterFunc<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.