Table of Contents

Class DataOptionsExtensions

Namespace
LinqToDB
Assembly
linq2db.dll

Set of extensions for DataOptions.

public static class DataOptionsExtensions
Inheritance
DataOptionsExtensions

Methods

RemoveInterceptor(DataOptions, IInterceptor)

Removes IInterceptor instance from the context.

public static DataOptions RemoveInterceptor(this DataOptions options, IInterceptor interceptor)

Parameters

options DataOptions
interceptor IInterceptor

Returns

DataOptions

UseAccess(DataOptions, string, Func<AccessOptions, AccessOptions>?)

Configure connection to use Access default provider and connection string.

public static DataOptions UseAccess(this DataOptions options, string connectionString, Func<AccessOptions, AccessOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

Access connection string.

optionSetter Func<AccessOptions, AccessOptions>

Optional AccessOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

Remarks

Default provider determined by inspecting connection string for OleDb or ODBC-specific markers and otherwise defaults to OleDb provider.

For more fine-grained configuration see UseAccessOleDb(DataOptions, string, Func<AccessOptions, AccessOptions>?) and UseAccessOdbc(DataOptions, Func<AccessOptions, AccessOptions>?) methods.

UseAccessOdbc(DataOptions, Func<AccessOptions, AccessOptions>?)

Configure connection to use Access ODBC provider.

public static DataOptions UseAccessOdbc(this DataOptions options, Func<AccessOptions, AccessOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

optionSetter Func<AccessOptions, AccessOptions>

Optional AccessOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseAccessOdbc(DataOptions, string, Func<AccessOptions, AccessOptions>?)

Configure connection to use Access ODBC provider and connection string.

public static DataOptions UseAccessOdbc(this DataOptions options, string connectionString, Func<AccessOptions, AccessOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

Access connection string.

optionSetter Func<AccessOptions, AccessOptions>

Optional AccessOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseAccessOleDb(DataOptions, Func<AccessOptions, AccessOptions>?)

Configure connection to use Access OleDb provider.

public static DataOptions UseAccessOleDb(this DataOptions options, Func<AccessOptions, AccessOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

optionSetter Func<AccessOptions, AccessOptions>

Optional AccessOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseAccessOleDb(DataOptions, string, Func<AccessOptions, AccessOptions>?)

Configure connection to use Access OleDb provider and connection string.

public static DataOptions UseAccessOleDb(this DataOptions options, string connectionString, Func<AccessOptions, AccessOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

Access connection string.

optionSetter Func<AccessOptions, AccessOptions>

Optional AccessOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseAfterConnectionOpened(DataOptions, Action<DbConnection>, Func<DbConnection, CancellationToken, Task>?)

Sets custom actions, executed after connection opened.

public static DataOptions UseAfterConnectionOpened(this DataOptions options, Action<DbConnection> afterConnectionOpened, Func<DbConnection, CancellationToken, Task>? afterConnectionOpenedAsync = null)

Parameters

options DataOptions
afterConnectionOpened Action<DbConnection>

Action, executed for connection instance after Open() call. Also called after OpenAsync(CancellationToken) call if afterConnectionOpenedAsync action is not provided. Accepts connection instance as parameter.

afterConnectionOpenedAsync Func<DbConnection, CancellationToken, Task>

Action, executed for connection instance from async execution path after OpenAsync(CancellationToken) call. Accepts connection instance as parameter. If this option is not set, afterConnectionOpened synchronous action called. Use this option only if you need to perform async work from action, otherwise afterConnectionOpened is sufficient.

Returns

DataOptions

UseAse(DataOptions, Func<SybaseOptions, SybaseOptions>?)

Configure connection to use SAP/Sybase ASE default provider.

public static DataOptions UseAse(this DataOptions options, Func<SybaseOptions, SybaseOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

optionSetter Func<SybaseOptions, SybaseOptions>

Optional SybaseOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

Remarks

Provider selection available only for .NET Framework applications.

Default provider will be chosen by probing current folder for provider assembly and if it is not found, default to official Sybase.AdoNet45.AseClient provider.

UseAse(DataOptions, string, bool, Func<SybaseOptions, SybaseOptions>?)

Configure connection to use specific SAP/Sybase ASE provider and connection string.

public static DataOptions UseAse(this DataOptions options, string connectionString, bool useNativeProvider, Func<SybaseOptions, SybaseOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

SAP/Sybase ASE connection string.

useNativeProvider bool

if true, Sybase.AdoNet45.AseClient provider will be used; otherwise managed AdoNetCore.AseClient.

optionSetter Func<SybaseOptions, SybaseOptions>

Optional SybaseOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseAse(DataOptions, string, Func<SybaseOptions, SybaseOptions>?)

Configure connection to use SAP/Sybase ASE default provider and connection string.

public static DataOptions UseAse(this DataOptions options, string connectionString, Func<SybaseOptions, SybaseOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

SAP/Sybase ASE connection string.

optionSetter Func<SybaseOptions, SybaseOptions>

Optional SybaseOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

Remarks

Provider selection available only for .NET Framework applications.

Default provider will be choosen by probing current folder for provider assembly and if it is not found, default to official Sybase.AdoNet45.AseClient provider.

UseBeforeConnectionOpened(DataOptions, Action<DbConnection>, Func<DbConnection, CancellationToken, Task>?)

Sets custom actions, executed before connection opened.

public static DataOptions UseBeforeConnectionOpened(this DataOptions options, Action<DbConnection> afterConnectionOpening, Func<DbConnection, CancellationToken, Task>? afterConnectionOpeningAsync = null)

Parameters

options DataOptions
afterConnectionOpening Action<DbConnection>

Action, executed before database connection opened. Accepts connection instance as parameter.

afterConnectionOpeningAsync Func<DbConnection, CancellationToken, Task>

Action, executed after database connection opened from async execution path. Accepts connection instance as parameter. If this option is not set, afterConnectionOpening synchronous action called. Use this option only if you need to perform async work from action, otherwise afterConnectionOpening is sufficient.

Returns

DataOptions

UseBulkCopyCheckConstraints(DataOptions, bool?)

Enables database constrains enforcement during bulk copy operation. Supported with ProviderSpecific bulk copy mode for following databases:

  • Oracle
  • SQL Server
  • SAP/Sybase ASE
public static DataOptions UseBulkCopyCheckConstraints(this DataOptions options, bool? checkConstraints)

Parameters

options DataOptions
checkConstraints bool?

Returns

DataOptions

UseBulkCopyDatabaseName(DataOptions, string?)

Gets or sets explicit name of target database instead of one, configured for copied entity in mapping schema. See DatabaseName<T>(ITable<T>, string?) method for support information per provider.

public static DataOptions UseBulkCopyDatabaseName(this DataOptions options, string? databaseName)

Parameters

options DataOptions
databaseName string

Returns

DataOptions

UseBulkCopyFireTriggers(DataOptions, bool?)

Enables insert triggers during bulk copy operation. Supported with ProviderSpecific bulk copy mode for following databases:

  • Oracle
  • SQL Server
  • SAP/Sybase ASE
public static DataOptions UseBulkCopyFireTriggers(this DataOptions options, bool? fireTriggers)

Parameters

options DataOptions
fireTriggers bool?

Returns

DataOptions

UseBulkCopyKeepIdentity(DataOptions, bool?)

If this option set to true, bulk copy will use values of columns, marked with IsIdentity flag. SkipOnInsert flag in this case will be ignored. Otherwise those columns will be skipped and values will be generated by server. Not compatible with RowByRow mode.

public static DataOptions UseBulkCopyKeepIdentity(this DataOptions options, bool? keepIdentity)

Parameters

options DataOptions
keepIdentity bool?

Returns

DataOptions

UseBulkCopyKeepNulls(DataOptions, bool?)

Enables instert of NULL values instead of values from colum default constraint during bulk copy operation. Supported with ProviderSpecific bulk copy mode for following databases:

  • SQL Server
  • SAP/Sybase ASE
public static DataOptions UseBulkCopyKeepNulls(this DataOptions options, bool? keepNulls)

Parameters

options DataOptions
keepNulls bool?

Returns

DataOptions

UseBulkCopyMaxBatchSize(DataOptions, int?)

Number of rows in each batch. At the end of each batch, the rows in the batch are sent to the server. Returns an integer value or zero if no value has been set.

public static DataOptions UseBulkCopyMaxBatchSize(this DataOptions options, int? maxBatchSize)

Parameters

options DataOptions
maxBatchSize int?

Returns

DataOptions

UseBulkCopyMaxDegreeOfParallelism(DataOptions, int?)

Implemented only by ClickHouse.Client provider. Defines number of connections, used for parallel insert in ProviderSpecific mode.

public static DataOptions UseBulkCopyMaxDegreeOfParallelism(this DataOptions options, int? maxDegreeOfParallelism)

Parameters

options DataOptions
maxDegreeOfParallelism int?

Returns

DataOptions

UseBulkCopyMaxParametersForBatch(DataOptions, int?)

If set, will override the Maximum parameters per batch statement from MaxParameters.

public static DataOptions UseBulkCopyMaxParametersForBatch(this DataOptions options, int? maxParametersForBatch)

Parameters

options DataOptions
maxParametersForBatch int?

Returns

DataOptions

UseBulkCopyNotifyAfter(DataOptions, int)

Gets or sets counter after how many copied records RowsCopiedCallback should be called. E.g. if you set it to 10, callback will be called after each 10 copied records. To disable callback, set this option to 0 (default value).

public static DataOptions UseBulkCopyNotifyAfter(this DataOptions options, int notifyAfter)

Parameters

options DataOptions
notifyAfter int

Returns

DataOptions

UseBulkCopyRowsCopiedCallback(DataOptions, Action<BulkCopyRowsCopied>?)

Gets or sets callback method that will be called by BulkCopy operation after each NotifyAfter rows copied. This callback will not be used if NotifyAfter set to 0.

public static DataOptions UseBulkCopyRowsCopiedCallback(this DataOptions options, Action<BulkCopyRowsCopied>? rowsCopiedCallback)

Parameters

options DataOptions
rowsCopiedCallback Action<BulkCopyRowsCopied>

Returns

DataOptions

UseBulkCopySchemaName(DataOptions, string?)

Gets or sets explicit name of target schema/owner instead of one, configured for copied entity in mapping schema. See SchemaName<T>(ITable<T>, string?) method for support information per provider.

public static DataOptions UseBulkCopySchemaName(this DataOptions options, string? schemaName)

Parameters

options DataOptions
schemaName string

Returns

DataOptions

UseBulkCopyServerName(DataOptions, string?)

Gets or sets explicit name of target server instead of one, configured for copied entity in mapping schema. See ServerName<T>(ITable<T>, string?) method for support information per provider. Also note that it is not supported by provider-specific insert method.

public static DataOptions UseBulkCopyServerName(this DataOptions options, string? serverName)

Parameters

options DataOptions
serverName string

Returns

DataOptions

UseBulkCopyTableLock(DataOptions, bool?)

Applies table lock during bulk copy operation. Supported with ProviderSpecific bulk copy mode for following databases:

  • DB2
  • Informix (using DB2 provider)
  • SQL Server
  • SAP/Sybase ASE
public static DataOptions UseBulkCopyTableLock(this DataOptions options, bool? tableLock)

Parameters

options DataOptions
tableLock bool?

Returns

DataOptions

UseBulkCopyTableName(DataOptions, string?)

Gets or sets explicit name of target table instead of one, configured for copied entity in mapping schema.

public static DataOptions UseBulkCopyTableName(this DataOptions options, string? tableName)

Parameters

options DataOptions
tableName string

Returns

DataOptions

UseBulkCopyTableOptions(DataOptions, TableOptions)

Gets or sets TableOptions flags overrides instead of configured for copied entity in mapping schema. See IsTemporary<T>(ITable<T>, bool) method for support information per provider.

public static DataOptions UseBulkCopyTableOptions(this DataOptions options, TableOptions tableOptions)

Parameters

options DataOptions
tableOptions TableOptions

Returns

DataOptions

UseBulkCopyTimeout(DataOptions, int?)

Number of seconds for the operation to complete before it times out.

public static DataOptions UseBulkCopyTimeout(this DataOptions options, int? bulkCopyTimeout)

Parameters

options DataOptions
bulkCopyTimeout int?

Returns

DataOptions

UseBulkCopyType(DataOptions, BulkCopyType)

Specify bulk copy implementation type.

public static DataOptions UseBulkCopyType(this DataOptions options, BulkCopyType bulkCopyType)

Parameters

options DataOptions
bulkCopyType BulkCopyType

Returns

DataOptions

UseBulkCopyUseInternalTransaction(DataOptions, bool?)

Enables automatic transaction creation during bulk copy operation. Supported with ProviderSpecific bulk copy mode for following databases:

  • Oracle
  • SQL Server
  • SAP/Sybase ASE
public static DataOptions UseBulkCopyUseInternalTransaction(this DataOptions options, bool? useInternalTransaction)

Parameters

options DataOptions
useInternalTransaction bool?

Returns

DataOptions

UseBulkCopyUseParameters(DataOptions, bool)

Gets or sets whether to Always use Parameters for MultipleRowsCopy. Default is false. If True, provider's override for MaxParameters will be used to determine the maximum number of rows per insert, Unless overridden by MaxParametersForBatch.

public static DataOptions UseBulkCopyUseParameters(this DataOptions options, bool useParameters)

Parameters

options DataOptions
useParameters bool

Returns

DataOptions

UseBulkCopyWithoutSession(DataOptions, bool)

Implemented only by ClickHouse.Client provider. When set, provider-specific bulk copy will use session-less connection even if called over connection with session. Note that session-less connections cannot be used with session-bound functionality like temporary tables.

public static DataOptions UseBulkCopyWithoutSession(this DataOptions options, bool withoutSession)

Parameters

options DataOptions
withoutSession bool

Returns

DataOptions

UseCacheSlidingExpiration(DataOptions, TimeSpan?)

Specifies timeout when query will be evicted from cache since last execution of query. Default value is 1 hour.

public static DataOptions UseCacheSlidingExpiration(this DataOptions options, TimeSpan? cacheSlidingExpiration)

Parameters

options DataOptions
cacheSlidingExpiration TimeSpan?

Returns

DataOptions

UseClickHouse(DataOptions, ClickHouseProvider, Func<ClickHouseOptions, ClickHouseOptions>?)

Configure connection to use UseClickHouse provider.

public static DataOptions UseClickHouse(this DataOptions options, ClickHouseProvider provider, Func<ClickHouseOptions, ClickHouseOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

provider ClickHouseProvider

ClickHouse provider.

optionSetter Func<ClickHouseOptions, ClickHouseOptions>

Optional ClickHouseOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseClickHouse(DataOptions, ClickHouseProvider, string, Func<ClickHouseOptions, ClickHouseOptions>?)

Configure connection to use UseClickHouse provider and connection string.

public static DataOptions UseClickHouse(this DataOptions options, ClickHouseProvider provider, string connectionString, Func<ClickHouseOptions, ClickHouseOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

provider ClickHouseProvider

ClickHouse provider.

connectionString string

ClickHouse connection string.

optionSetter Func<ClickHouseOptions, ClickHouseOptions>

Optional ClickHouseOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseCoefficient(DataOptions, TimeSpan)

The coefficient for the exponential function used to compute the delay between retries, must be nonnegative. Default value: 1 second.

public static DataOptions UseCoefficient(this DataOptions options, TimeSpan coefficient)

Parameters

options DataOptions
coefficient TimeSpan

Returns

DataOptions

UseCompareNullsAsValues(DataOptions, bool)

If set to true nullable fields would be checked for IS NULL in Equal/NotEqual comparisons. This affects: Equal, NotEqual, Not Contains Default value: true.

public static DataOptions UseCompareNullsAsValues(this DataOptions options, bool compareNullsAsValues)

Parameters

options DataOptions
compareNullsAsValues bool

Returns

DataOptions

Examples

public class MyEntity
{
    public int? Value;
}

db.MyEntity.Where(e => e.Value != 10)

from e1 in db.MyEntity
join e2 in db.MyEntity on e1.Value equals e2.Value
select e1

var filter = new [] {1, 2, 3};
db.MyEntity.Where(e => ! filter.Contains(e.Value))

Would be converted to next queries:

SELECT Value FROM MyEntity WHERE Value IS NULL OR Value != 10

 SELECT e1.Value
 FROM MyEntity e1
 INNER JOIN MyEntity e2 ON e1.Value = e2.Value OR (e1.Value IS NULL AND e2.Value IS NULL)

 SELECT Value FROM MyEntity WHERE Value IS NULL OR NOT Value IN (1, 2, 3)

UseConfiguration(DataOptions, string?)

Defines configuration sting to use with DataOptions.

public static DataOptions UseConfiguration(this DataOptions options, string? configurationString)

Parameters

options DataOptions
configurationString string

Returns

DataOptions

UseConfiguration(DataOptions, string, MappingSchema)

Defines configuration sting and MappingSchema to use with DataOptions.

public static DataOptions UseConfiguration(this DataOptions options, string configurationString, MappingSchema mappingSchema)

Parameters

options DataOptions
configurationString string
mappingSchema MappingSchema

Returns

DataOptions

UseConfigurationString(DataOptions, string?)

Defines configuration sting to use with DataOptions.

public static DataOptions UseConfigurationString(this DataOptions options, string? configurationString)

Parameters

options DataOptions
configurationString string

Returns

DataOptions

UseConfigurationString(DataOptions, string, MappingSchema)

Defines configuration sting and MappingSchema to use with DataOptions.

public static DataOptions UseConfigurationString(this DataOptions options, string configurationString, MappingSchema mappingSchema)

Parameters

options DataOptions
configurationString string
mappingSchema MappingSchema

Returns

DataOptions

UseConnection(DataOptions, IDataProvider, DbConnection)

Defines data provider and DbConnection to use with DataOptions.

public static DataOptions UseConnection(this DataOptions options, IDataProvider dataProvider, DbConnection connection)

Parameters

options DataOptions
dataProvider IDataProvider
connection DbConnection

Returns

DataOptions

UseConnection(DataOptions, IDataProvider, DbConnection, bool)

Defines data provider and DbConnection to use with DataOptions.

public static DataOptions UseConnection(this DataOptions options, IDataProvider dataProvider, DbConnection connection, bool disposeConnection)

Parameters

options DataOptions
dataProvider IDataProvider
connection DbConnection
disposeConnection bool

Returns

DataOptions

UseConnection(DataOptions, DbConnection)

Defines DbConnection to use with DataOptions.

public static DataOptions UseConnection(this DataOptions options, DbConnection connection)

Parameters

options DataOptions
connection DbConnection

Returns

DataOptions

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

Defines data provider and connection factory to use with DataOptions.

public static DataOptions UseConnectionFactory(this DataOptions options, IDataProvider dataProvider, Func<DataOptions, DbConnection> connectionFactory)

Parameters

options DataOptions
dataProvider IDataProvider
connectionFactory Func<DataOptions, DbConnection>

Returns

DataOptions

UseConnectionFactory(DataOptions, Func<DataOptions, DbConnection>)

Defines connection factory to use with DataOptions.

public static DataOptions UseConnectionFactory(this DataOptions options, Func<DataOptions, DbConnection> connectionFactory)

Parameters

options DataOptions
connectionFactory Func<DataOptions, DbConnection>

Returns

DataOptions

UseConnectionString(DataOptions, IDataProvider, string)

Defines data provider and connection sting to use with DataOptions.

public static DataOptions UseConnectionString(this DataOptions options, IDataProvider dataProvider, string connectionString)

Parameters

options DataOptions
dataProvider IDataProvider
connectionString string

Returns

DataOptions

UseConnectionString(DataOptions, string)

Defines connection sting to use with DataOptions.

public static DataOptions UseConnectionString(this DataOptions options, string connectionString)

Parameters

options DataOptions
connectionString string

Returns

DataOptions

UseConnectionString(DataOptions, string, string)

Defines provider name and connection sting to use with DataOptions.

public static DataOptions UseConnectionString(this DataOptions options, string providerName, string connectionString)

Parameters

options DataOptions
providerName string
connectionString string

Returns

DataOptions

UseDB2(DataOptions, DB2Version, Func<DB2Options, DB2Options>?)

Configure connection to use specific DB2 provider.

public static DataOptions UseDB2(this DataOptions options, DB2Version version, Func<DB2Options, DB2Options>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

version DB2Version

DB2 server version.

optionSetter Func<DB2Options, DB2Options>

Optional DB2Options configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseDB2(DataOptions, string, DB2Version, Func<DB2Options, DB2Options>?)

Configure connection to use specific DB2 provider and connection string.

public static DataOptions UseDB2(this DataOptions options, string connectionString, DB2Version version, Func<DB2Options, DB2Options>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

DB2 connection string.

version DB2Version

DB2 server version.

optionSetter Func<DB2Options, DB2Options>

Optional DB2Options configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseDB2(DataOptions, string, Func<DB2Options, DB2Options>?)

Configure connection to use DB2 default provider and connection string.

public static DataOptions UseDB2(this DataOptions options, string connectionString, Func<DB2Options, DB2Options>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

DB2 connection string.

optionSetter Func<DB2Options, DB2Options>

Optional DB2Options configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

Remarks

DB2 provider will be chosen automatically:

  • if AutoDetectProvider (default: true) enabled, LinqToDB will query server for version
  • otherwise DB2 LUW provider will be chosen.
For more fine-grained configuration see UseDB2(DataOptions, string, DB2Version, Func<DB2Options, DB2Options>?) overload.

UseDataProvider(DataOptions, IDataProvider)

Defines data provider to use with DataOptions.

public static DataOptions UseDataProvider(this DataOptions options, IDataProvider dataProvider)

Parameters

options DataOptions
dataProvider IDataProvider

Returns

DataOptions

UseDataProviderFactory(DataOptions, Func<ConnectionOptions, IDataProvider>)

Sets DataProviderFactory option.

public static DataOptions UseDataProviderFactory(this DataOptions options, Func<ConnectionOptions, IDataProvider> dataProviderFactory)

Parameters

options DataOptions
dataProviderFactory Func<ConnectionOptions, IDataProvider>

Returns

DataOptions

UseDefaultRetryPolicyFactory(DataOptions)

Uses default retry policy factory.

public static DataOptions UseDefaultRetryPolicyFactory(this DataOptions options)

Parameters

options DataOptions

Returns

DataOptions

UseDisableQueryCache(DataOptions, bool)

Used to disable LINQ expressions caching for queries. This cache reduces time, required for query parsing but have several side-effects:

- cached LINQ expressions could contain references to external objects as parameters, which could lead to memory leaks if those objects are not used anymore by other code

- cache access synchronization could lead to bigger latencies than it saves.

Default value: false.

It is not recommended to enable this option as it could lead to severe slowdown. Better approach will be to call ClearCache() method to cleanup cache after queries, that produce severe memory leaks you need to fix.

More details.
public static DataOptions UseDisableQueryCache(this DataOptions options, bool disableQueryCache)

Parameters

options DataOptions
disableQueryCache bool

Returns

DataOptions

UseDoNotClearOrderBys(DataOptions, bool)

Controls behavior, when LINQ query chain contains multiple OrderBy<TSource, TKey>(IQueryable<TSource>, Expression<Func<TSource, TKey>>) or OrderByDescending<TSource, TKey>(IQueryable<TSource>, Expression<Func<TSource, TKey>>) calls:

  • if true - non-first OrderBy* call will be treated as ThenBy* call;
  • if false - OrderBy* call will discard sort specifications, added by previous OrderBy* and ThenBy* calls. Default value: false.
public static DataOptions UseDoNotClearOrderBys(this DataOptions options, bool doNotClearOrderBys)

Parameters

options DataOptions
doNotClearOrderBys bool

Returns

DataOptions

UseEnableConstantExpressionInOrderBy(DataOptions, bool)

If true, linq2db will allow any constant expressions in ORDER BY clause. Default value: false.

public static DataOptions UseEnableConstantExpressionInOrderBy(this DataOptions options, bool enableConstantExpressionInOrderBy)

Parameters

options DataOptions
enableConstantExpressionInOrderBy bool

Returns

DataOptions

UseEnableContextSchemaEdit(DataOptions, bool)

If true, user could add new mappings to context mapping schems (MappingSchema). Otherwise, LinqToDBException will be generated on locked mapping schema edit attempt. It is not recommended to enable this option as it has performance implications. Proper approach is to create single MappingSchema instance once, configure mappings for it and use this MappingSchema instance for all context instances.

public static DataOptions UseEnableContextSchemaEdit(this DataOptions options, bool enableContextSchemaEdit)

Parameters

options DataOptions
enableContextSchemaEdit bool

Returns

DataOptions

UseExponentialBase(DataOptions, double)

The base for the exponential function used to compute the delay between retries, must be positive. Default value: 2.

public static DataOptions UseExponentialBase(this DataOptions options, double exponentialBase)

Parameters

options DataOptions
exponentialBase double

Returns

DataOptions

UseFactory(DataOptions, Func<DataConnection, IRetryPolicy?>?)

Retry policy factory method, used to create retry policy for new DataConnection instance. If factory method is not set, retry policy is not used. Not set by default.

public static DataOptions UseFactory(this DataOptions options, Func<DataConnection, IRetryPolicy?>? factory)

Parameters

options DataOptions
factory Func<DataConnection, IRetryPolicy>

Returns

DataOptions

UseFirebird(DataOptions, Func<FirebirdOptions, FirebirdOptions>?)

Configure connection to use Firebird provider.

public static DataOptions UseFirebird(this DataOptions options, Func<FirebirdOptions, FirebirdOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

optionSetter Func<FirebirdOptions, FirebirdOptions>

Optional FirebirdOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseFirebird(DataOptions, string, Func<FirebirdOptions, FirebirdOptions>?)

Configure connection to use Firebird provider and connection string.

public static DataOptions UseFirebird(this DataOptions options, string connectionString, Func<FirebirdOptions, FirebirdOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

Firebird connection string.

optionSetter Func<FirebirdOptions, FirebirdOptions>

Optional FirebirdOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseGenerateExpressionTest(DataOptions, bool)

Enables generation of test class for each LINQ query, executed while this option is enabled. This option could be useful for issue reporting, when you need to provide reproducible case. Test file will be placed to linq2db subfolder of temp folder and exact file path will be logged to data connection tracing infrastructure. See TraceSwitch for more details. Default value: false.

public static DataOptions UseGenerateExpressionTest(this DataOptions options, bool generateExpressionTest)

Parameters

options DataOptions
generateExpressionTest bool

Returns

DataOptions

UseGenerateFinalAliases(DataOptions, bool)

Indicates whether SQL Builder should generate aliases for final projection. It is not required for correct query processing but simplifies SQL analysis.

Default value: false.

For the query
var query = from child in db.Child
   select new
   {
      TrackId = child.ChildID,
   };
When property is true
SELECT
                                                        [child].[ChildID] as [TrackId]
                                                     FROM
                                                        [Child] [child]
Otherwise alias will be removed
SELECT
   [child].[ChildID]
FROM
   [Child] [child]
public static DataOptions UseGenerateFinalAliases(this DataOptions options, bool generateFinalAliases)

Parameters

options DataOptions
generateFinalAliases bool

Returns

DataOptions

UseGuardGrouping(DataOptions, bool)

Controls behavior of LINQ query, which ends with GroupBy call.

public static DataOptions UseGuardGrouping(this DataOptions options, bool guardGrouping)

Parameters

options DataOptions
guardGrouping bool

Returns

DataOptions

Remarks

UseIgnoreEmptyUpdate(DataOptions, bool)

Controls behavior of linq2db when there is no updateable fields in Update query:

  • if true - query not executed and Update operation returns 0 as number of affected records;
  • if false - LinqToDBException will be thrown. Default value: false.
public static DataOptions UseIgnoreEmptyUpdate(DataOptions options, bool ignoreEmptyUpdate)

Parameters

options DataOptions
ignoreEmptyUpdate bool

Returns

DataOptions

UseInformix(DataOptions, Func<InformixOptions, InformixOptions>?)

Configure connection to use Informix default provider.

public static DataOptions UseInformix(this DataOptions options, Func<InformixOptions, InformixOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

optionSetter Func<InformixOptions, InformixOptions>

Optional InformixOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

Remarks

Default provider will be chosen by probing current folder for provider assembly and if it is not found, default to IBM.Data.DB2 provider. This is not applicable to .NET Core applications as they always use IBM.Data.DB2 provider.

UseInformix(DataOptions, string, bool, Func<InformixOptions, InformixOptions>?)

Configure connection to use specific Informix provider and connection string.

public static DataOptions UseInformix(this DataOptions options, string connectionString, bool useDB2Provider, Func<InformixOptions, InformixOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

Informix connection string.

useDB2Provider bool

if true, IBM.Data.DB2 provider will be used; otherwise IBM.Data.Informix.

optionSetter Func<InformixOptions, InformixOptions>

Optional InformixOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseInformix(DataOptions, string, Func<InformixOptions, InformixOptions>?)

Configure connection to use Informix default provider and connection string.

public static DataOptions UseInformix(this DataOptions options, string connectionString, Func<InformixOptions, InformixOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

Informix connection string.

optionSetter Func<InformixOptions, InformixOptions>

Optional InformixOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

Remarks

Default provider will be chosen by probing current folder for provider assembly and if it is not found, default to IBM.Data.DB2 provider. This is not applicable to .NET Core applications as they always use IBM.Data.DB2 provider.

UseInterceptor(DataOptions, IInterceptor)

Adds IInterceptor instance to those registered on the context.

Interceptors can be used to view, change, or suppress operations taken by linq2db. See the specific implementations of IInterceptor for details. For example, 'ICommandInterceptor'.

Extensions can also register multiple IInterceptors in the internal service provider. If both injected and application interceptors are found, then the injected interceptors are run in the order that they are resolved from the service provider, and then the application interceptors are run in the order that they were added to the context.

Calling this method multiple times will result in all interceptors in every call being added to the context. Interceptors added in a previous call are not overridden by interceptors added in a later call.

public static DataOptions UseInterceptor(this DataOptions options, IInterceptor interceptor)

Parameters

options DataOptions
interceptor IInterceptor

The interceptor to add.

Returns

DataOptions

The same builder instance so that multiple calls can be chained.

UseInterceptors(DataOptions, params IInterceptor[])

Adds IInterceptor instances to those registered on the context.

Interceptors can be used to view, change, or suppress operations taken by linq2db. See the specific implementations of IInterceptor for details. For example, 'ICommandInterceptor'.

Extensions can also register multiple IInterceptors in the internal service provider. If both injected and application interceptors are found, then the injected interceptors are run in the order that they are resolved from the service provider, and then the application interceptors are run in the order that they were added to the context.

Calling this method multiple times will result in all interceptors in every call being added to the context. Interceptors added in a previous call are not overridden by interceptors added in a later call.

public static DataOptions UseInterceptors(this DataOptions options, params IInterceptor[] interceptors)

Parameters

options DataOptions
interceptors IInterceptor[]

The interceptors to add.

Returns

DataOptions

The same builder instance so that multiple calls can be chained.

UseInterceptors(DataOptions, IEnumerable<IInterceptor>)

Adds IInterceptor instances to those registered on the context.

Interceptors can be used to view, change, or suppress operations taken by linq2db. See the specific implementations of IInterceptor for details. For example, 'ICommandInterceptor'.

A single interceptor instance can implement multiple different interceptor interfaces. I will be registered as an interceptor for all interfaces that it implements.

Extensions can also register multiple IInterceptors in the internal service provider. If both injected and application interceptors are found, then the injected interceptors are run in the order that they are resolved from the service provider, and then the application interceptors are run in the order that they were added to the context.

Calling this method multiple times will result in all interceptors in every call being added to the context. Interceptors added in a previous call are not overridden by interceptors added in a later call.

public static DataOptions UseInterceptors(this DataOptions options, IEnumerable<IInterceptor> interceptors)

Parameters

options DataOptions
interceptors IEnumerable<IInterceptor>

The interceptors to add.

Returns

DataOptions

The same builder instance so that multiple calls can be chained.

UseKeepDistinctOrdered(DataOptions, bool)

Allows SQL generation to automatically transform

SELECT DISTINCT value FROM Table ORDER BY date

Into GROUP BY equivalent if syntax is not supported Default value: true.

public static DataOptions UseKeepDistinctOrdered(this DataOptions options, bool keepDistinctOrdered)

Parameters

options DataOptions
keepDistinctOrdered bool

Returns

DataOptions

UseMappingSchema(DataOptions, MappingSchema)

Defines mapping schema to use with DataOptions.

public static DataOptions UseMappingSchema(this DataOptions options, MappingSchema mappingSchema)

Parameters

options DataOptions
mappingSchema MappingSchema

Returns

DataOptions

UseMaxDelay(DataOptions, TimeSpan)

The maximum time delay between retries, must be nonnegative. Default value: 30 seconds.

public static DataOptions UseMaxDelay(this DataOptions options, TimeSpan defaultMaxDelay)

Parameters

options DataOptions
defaultMaxDelay TimeSpan

Returns

DataOptions

UseMaxRetryCount(DataOptions, int)

The number of retry attempts. Default value: 5.

public static DataOptions UseMaxRetryCount(this DataOptions options, int maxRetryCount)

Parameters

options DataOptions
maxRetryCount int

Returns

DataOptions

UseMySql(DataOptions, Func<MySqlOptions, MySqlOptions>?)

Configure connection to use MySql default provider.

public static DataOptions UseMySql(this DataOptions options, Func<MySqlOptions, MySqlOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

optionSetter Func<MySqlOptions, MySqlOptions>

Optional MySqlOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

Remarks

Default provider will be chosen by probing current folder for provider assembly and if it is not found, default to MySql.Data provider.

UseMySql(DataOptions, string, Func<MySqlOptions, MySqlOptions>?)

Configure connection to use MySql default provider and connection string.

public static DataOptions UseMySql(this DataOptions options, string connectionString, Func<MySqlOptions, MySqlOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

MySql connection string.

optionSetter Func<MySqlOptions, MySqlOptions>

Optional MySqlOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

Remarks

Default provider will be chosen by probing current folder for provider assembly and if it is not found, default to MySql.Data provider.

UseMySqlConnector(DataOptions, Func<MySqlOptions, MySqlOptions>?)

Configure connection to use MySqlConnector MySql provider.

public static DataOptions UseMySqlConnector(this DataOptions options, Func<MySqlOptions, MySqlOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

optionSetter Func<MySqlOptions, MySqlOptions>

Optional MySqlOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseMySqlConnector(DataOptions, string, Func<MySqlOptions, MySqlOptions>?)

Configure connection to use MySqlConnector MySql provider and connection string.

public static DataOptions UseMySqlConnector(this DataOptions options, string connectionString, Func<MySqlOptions, MySqlOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

MySql connection string.

optionSetter Func<MySqlOptions, MySqlOptions>

Optional MySqlOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseMySqlData(DataOptions, Func<MySqlOptions, MySqlOptions>?)

Configure connection to use MySql.Data MySql provider.

public static DataOptions UseMySqlData(this DataOptions options, Func<MySqlOptions, MySqlOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

optionSetter Func<MySqlOptions, MySqlOptions>

Optional MySqlOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseMySqlData(DataOptions, string, Func<MySqlOptions, MySqlOptions>?)

Configure connection to use MySql.Data MySql provider and connection string.

public static DataOptions UseMySqlData(this DataOptions options, string connectionString, Func<MySqlOptions, MySqlOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

MySql connection string.

optionSetter Func<MySqlOptions, MySqlOptions>

Optional MySqlOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseOnEntityDescriptorCreated(DataOptions, Action<MappingSchema, IEntityChangeDescriptor>)

Defines entity descriptor creation callback to use with DataOptions.

public static DataOptions UseOnEntityDescriptorCreated(this DataOptions options, Action<MappingSchema, IEntityChangeDescriptor> onEntityDescriptorCreated)

Parameters

options DataOptions
onEntityDescriptorCreated Action<MappingSchema, IEntityChangeDescriptor>

Returns

DataOptions

UseOptimizeJoins(DataOptions, bool)

If enabled, linq2db will try to reduce number of generated SQL JOINs for LINQ query. Attempted optimizations:

  • removes duplicate joins by unique target table key;
  • removes self-joins by unique key;
  • removes left joins if joined table is not used in query. Default value: true.
public static DataOptions UseOptimizeJoins(this DataOptions options, bool optimizeJoins)

Parameters

options DataOptions
optimizeJoins bool

Returns

DataOptions

UseOracle(DataOptions, OracleVersion, OracleProvider, Func<OracleOptions, OracleOptions>?)

Configure connection to use specific Oracle provider, dialect and provider-specific options.

public static DataOptions UseOracle(this DataOptions options, OracleVersion dialect, OracleProvider provider, Func<OracleOptions, OracleOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

dialect OracleVersion

Oracle dialect support level.

provider OracleProvider

ADO.NET provider to use.

optionSetter Func<OracleOptions, OracleOptions>

Optional OracleOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseOracle(DataOptions, string, OracleProvider, Func<OracleOptions, OracleOptions>?)

Configure connection to use specific Oracle provider and connection string.

public static DataOptions UseOracle(this DataOptions options, string connectionString, OracleProvider provider, Func<OracleOptions, OracleOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

Oracle connection string.

provider OracleProvider

ADO.NET provider to use.

optionSetter Func<OracleOptions, OracleOptions>

Optional OracleOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseOracle(DataOptions, string, OracleVersion, OracleProvider, Func<OracleOptions, OracleOptions>?)

Configure connection to use specific Oracle provider, dialect and connection string.

public static DataOptions UseOracle(this DataOptions options, string connectionString, OracleVersion dialect, OracleProvider provider, Func<OracleOptions, OracleOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

Oracle connection string.

dialect OracleVersion

Oracle dialect support level.

provider OracleProvider

ADO.NET provider to use.

optionSetter Func<OracleOptions, OracleOptions>

Optional OracleOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseOracle(DataOptions, string, Func<OracleOptions, OracleOptions>?)

Configure connection to use Oracle default provider, specific dialect and connection string.

public static DataOptions UseOracle(this DataOptions options, string connectionString, Func<OracleOptions, OracleOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

Oracle connection string.

optionSetter Func<OracleOptions, OracleOptions>

Optional OracleOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

Remarks

By default LinqToDB tries to load managed version of Oracle provider.

UseParameterizeTakeSkip(DataOptions, bool)

Enables Take/Skip parameterization. Default value: true.

public static DataOptions UseParameterizeTakeSkip(this DataOptions options, bool parameterizeTakeSkip)

Parameters

options DataOptions
parameterizeTakeSkip bool

Returns

DataOptions

UsePostgreSQL(DataOptions, PostgreSQLVersion, Func<PostgreSQLOptions, PostgreSQLOptions>?)

Configure connection to use PostgreSQL Npgsql provider, specific dialect and provider-specific options.

public static DataOptions UsePostgreSQL(this DataOptions options, PostgreSQLVersion dialect = PostgreSQLVersion.AutoDetect, Func<PostgreSQLOptions, PostgreSQLOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

dialect PostgreSQLVersion

PostgreSQL dialect support level.

optionSetter Func<PostgreSQLOptions, PostgreSQLOptions>

Optional PostgreSQLOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UsePostgreSQL(DataOptions, string, PostgreSQLVersion, Func<PostgreSQLOptions, PostgreSQLOptions>?)

Configure connection to use PostgreSQL Npgsql provider, specific dialect, provider-specific options and connection string.

public static DataOptions UsePostgreSQL(this DataOptions options, string connectionString, PostgreSQLVersion dialect = PostgreSQLVersion.AutoDetect, Func<PostgreSQLOptions, PostgreSQLOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

PostgreSQL connection string.

dialect PostgreSQLVersion

PostgreSQL dialect support level.

optionSetter Func<PostgreSQLOptions, PostgreSQLOptions>

Optional PostgreSQLOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UsePostgreSQL(DataOptions, string, Func<PostgreSQLOptions, PostgreSQLOptions>)

Configure connection to use PostgreSQL Npgsql provider, default dialect and connection string.

public static DataOptions UsePostgreSQL(this DataOptions options, string connectionString, Func<PostgreSQLOptions, PostgreSQLOptions> optionSetter)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

PostgreSQL connection string.

optionSetter Func<PostgreSQLOptions, PostgreSQLOptions>

PostgreSQLOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

Remarks

PostgreSQL dialect will be chosen automatically:

  • if AutoDetectProvider (default: true) enabled, LinqToDB will query server for version
  • otherwise v92 will be used as default dialect.
For more fine-grained configuration see UsePostgreSQL(DataOptions, string, PostgreSQLVersion, Func<PostgreSQLOptions, PostgreSQLOptions>?) overload.

UsePreferApply(DataOptions, bool)

Used to generate CROSS APPLY or OUTER APPLY if possible. Default value: true.

public static DataOptions UsePreferApply(this DataOptions options, bool preferApply)

Parameters

options DataOptions
preferApply bool

Returns

DataOptions

UsePreferExistsForScalar(DataOptions, bool)

Depending on this option linq2db generates different SQL for sequence.Contains(value).
true - EXISTS (SELECT * FROM sequence WHERE sequence.key = value).
false - value IN (SELECT sequence.key FROM sequence).
Default value: false.

public static DataOptions UsePreferExistsForScalar(this DataOptions options, bool preferExistsForScalar)

Parameters

options DataOptions
preferExistsForScalar bool

Returns

DataOptions

UsePreloadGroups(DataOptions, bool)

Controls how group data for LINQ queries ended with GroupBy will be loaded:

  • if true - group data will be loaded together with main query, resulting in 1 + N queries, where N - number of groups;
  • if false - group data will be loaded when you call enumerator for specific group IGrouping<TKey, TElement>. Default value: false.
public static DataOptions UsePreloadGroups(this DataOptions options, bool preloadGroups)

Parameters

options DataOptions
preloadGroups bool

Returns

DataOptions

UseProvider(DataOptions, string)

Defines provider name to use with DataOptions.

public static DataOptions UseProvider(this DataOptions options, string providerName)

Parameters

options DataOptions
providerName string

Returns

DataOptions

UseRandomFactor(DataOptions, double)

The maximum random factor, must not be lesser than 1. Default value: 1.1.

public static DataOptions UseRandomFactor(this DataOptions options, double randomFactor)

Parameters

options DataOptions
randomFactor double

Returns

DataOptions

UseRetryPolicy(DataOptions, IRetryPolicy)

Uses retry policy.

public static DataOptions UseRetryPolicy(this DataOptions options, IRetryPolicy retryPolicy)

Parameters

options DataOptions
retryPolicy IRetryPolicy

Returns

DataOptions

UseSQLite(DataOptions, Func<SQLiteOptions, SQLiteOptions>?)

Configure connection to use SQLite default provider.

public static DataOptions UseSQLite(this DataOptions options, Func<SQLiteOptions, SQLiteOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

optionSetter Func<SQLiteOptions, SQLiteOptions>

Optional SQLiteOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

Remarks

Default provider will be chosen by probing current folder for provider assembly and if it is not found, default to System.Data.Sqlite provider.

For more fine-grained configuration see UseSQLiteOfficial(DataOptions, string, Func<SQLiteOptions, SQLiteOptions>?) and UseSQLiteMicrosoft(DataOptions, string, Func<SQLiteOptions, SQLiteOptions>?) methods.

UseSQLite(DataOptions, string, Func<SQLiteOptions, SQLiteOptions>?)

Configure connection to use SQLite default provider and connection string.

public static DataOptions UseSQLite(this DataOptions options, string connectionString, Func<SQLiteOptions, SQLiteOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

SQLite connection string.

optionSetter Func<SQLiteOptions, SQLiteOptions>

Optional SQLiteOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

Remarks

Default provider will be chosen by probing current folder for provider assembly and if it is not found, default to System.Data.Sqlite provider.

For more fine-grained configuration see UseSQLiteOfficial(DataOptions, string, Func<SQLiteOptions, SQLiteOptions>?) and UseSQLiteMicrosoft(DataOptions, string, Func<SQLiteOptions, SQLiteOptions>?) methods.

UseSQLiteMicrosoft(DataOptions, Func<SQLiteOptions, SQLiteOptions>?)

Configure connection to use Microsoft.Data.Sqlite SQLite provider.

public static DataOptions UseSQLiteMicrosoft(this DataOptions options, Func<SQLiteOptions, SQLiteOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

optionSetter Func<SQLiteOptions, SQLiteOptions>

Optional SQLiteOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseSQLiteMicrosoft(DataOptions, string, Func<SQLiteOptions, SQLiteOptions>?)

Configure connection to use Microsoft.Data.Sqlite SQLite provider and connection string.

public static DataOptions UseSQLiteMicrosoft(this DataOptions options, string connectionString, Func<SQLiteOptions, SQLiteOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

SQLite connection string.

optionSetter Func<SQLiteOptions, SQLiteOptions>

Optional SQLiteOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseSQLiteOfficial(DataOptions, Func<SQLiteOptions, SQLiteOptions>?)

Configure connection to use System.Data.Sqlite SQLite provider.

public static DataOptions UseSQLiteOfficial(this DataOptions options, Func<SQLiteOptions, SQLiteOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

optionSetter Func<SQLiteOptions, SQLiteOptions>

Optional SQLiteOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseSQLiteOfficial(DataOptions, string, Func<SQLiteOptions, SQLiteOptions>?)

Configure connection to use System.Data.Sqlite SQLite provider and connection string.

public static DataOptions UseSQLiteOfficial(this DataOptions options, string connectionString, Func<SQLiteOptions, SQLiteOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

SQLite connection string.

optionSetter Func<SQLiteOptions, SQLiteOptions>

Optional SQLiteOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseSapHana(DataOptions, Func<SapHanaOptions, SapHanaOptions>?)

Configure connection to use SAP HANA default provider.

public static DataOptions UseSapHana(this DataOptions options, Func<SapHanaOptions, SapHanaOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

optionSetter Func<SapHanaOptions, SapHanaOptions>

Optional SapHanaOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

Remarks

Default provider will be Sap.Data.Hana native provider for .NET Framework and .NET Core applications and ODBC provider for .NET STANDARD builds.

UseSapHana(DataOptions, string, Func<SapHanaOptions, SapHanaOptions>?)

Configure connection to use SAP HANA default provider and connection string.

public static DataOptions UseSapHana(this DataOptions options, string connectionString, Func<SapHanaOptions, SapHanaOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

SAP HANA connection string.

optionSetter Func<SapHanaOptions, SapHanaOptions>

Optional SapHanaOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

Remarks

Default provider will be Sap.Data.Hana native provider for .NET Framework and .NET Core applications and ODBC provider for .NET STANDARD builds.

UseSapHanaNative(DataOptions, Func<SapHanaOptions, SapHanaOptions>?)

Configure connection to use native SAP HANA provider.

public static DataOptions UseSapHanaNative(this DataOptions options, Func<SapHanaOptions, SapHanaOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

optionSetter Func<SapHanaOptions, SapHanaOptions>

Optional SapHanaOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseSapHanaNative(DataOptions, string, Func<SapHanaOptions, SapHanaOptions>?)

Configure connection to use native SAP HANA provider and connection string.

public static DataOptions UseSapHanaNative(this DataOptions options, string connectionString, Func<SapHanaOptions, SapHanaOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

SAP HANA connection string.

optionSetter Func<SapHanaOptions, SapHanaOptions>

Optional SapHanaOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseSapHanaODBC(DataOptions, Func<SapHanaOptions, SapHanaOptions>?)

Configure connection to use SAP HANA ODBC provider.

public static DataOptions UseSapHanaODBC(this DataOptions options, Func<SapHanaOptions, SapHanaOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

optionSetter Func<SapHanaOptions, SapHanaOptions>

Optional SapHanaOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseSapHanaODBC(DataOptions, string, Func<SapHanaOptions, SapHanaOptions>?)

Configure connection to use SAP HANA ODBC provider and connection string.

public static DataOptions UseSapHanaODBC(this DataOptions options, string connectionString, Func<SapHanaOptions, SapHanaOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

SAP HANA connection string.

optionSetter Func<SapHanaOptions, SapHanaOptions>

Optional SapHanaOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseSqlCe(DataOptions, Func<SqlCeOptions, SqlCeOptions>?)

Configure connection to use SQL CE provider.

public static DataOptions UseSqlCe(this DataOptions options, Func<SqlCeOptions, SqlCeOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

optionSetter Func<SqlCeOptions, SqlCeOptions>

Optional SqlCeOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseSqlCe(DataOptions, string, Func<SqlCeOptions, SqlCeOptions>?)

Configure connection to use SQL CE provider and connection string.

public static DataOptions UseSqlCe(this DataOptions options, string connectionString, Func<SqlCeOptions, SqlCeOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

SQL CE connection string.

optionSetter Func<SqlCeOptions, SqlCeOptions>

Optional SqlCeOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseSqlServer(DataOptions, SqlServerVersion, SqlServerProvider, Func<SqlServerOptions, SqlServerOptions>?)

Configure connection to use specific SQL Server provider, dialect and provider-specific options.

public static DataOptions UseSqlServer(this DataOptions options, SqlServerVersion dialect = SqlServerVersion.AutoDetect, SqlServerProvider provider = SqlServerProvider.AutoDetect, Func<SqlServerOptions, SqlServerOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

dialect SqlServerVersion

SQL Server dialect support level.

provider SqlServerProvider

SQL Server provider to use.

optionSetter Func<SqlServerOptions, SqlServerOptions>

Optional SqlServerOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseSqlServer(DataOptions, string, SqlServerVersion, SqlServerProvider, Func<SqlServerOptions, SqlServerOptions>?)

Configure connection to use specific SQL Server provider, dialect, connection string and provider-specific options.

public static DataOptions UseSqlServer(this DataOptions options, string connectionString, SqlServerVersion dialect = SqlServerVersion.AutoDetect, SqlServerProvider provider = SqlServerProvider.AutoDetect, Func<SqlServerOptions, SqlServerOptions>? optionSetter = null)

Parameters

options DataOptions

Instance of DataOptions.

connectionString string

SQL Server connection string.

dialect SqlServerVersion

SQL Server dialect support level.

provider SqlServerProvider

SQL Server provider to use.

optionSetter Func<SqlServerOptions, SqlServerOptions>

Optional SqlServerOptions configuration callback.

Returns

DataOptions

The builder instance so calls can be chained.

UseTraceLevel(DataOptions, TraceLevel)

Configure the database to use specified trace level.

public static DataOptions UseTraceLevel(this DataOptions options, TraceLevel traceLevel)

Parameters

options DataOptions
traceLevel TraceLevel

Returns

DataOptions

The builder instance so calls can be chained.

UseTraceMapperExpression(DataOptions, bool)

Enables logging of generated mapping expression to data connection tracing infrastructure. See TraceSwitch for more details. Default value: false.

public static DataOptions UseTraceMapperExpression(this DataOptions options, bool traceMapperExpression)

Parameters

options DataOptions
traceMapperExpression bool

Returns

DataOptions

UseTraceWith(DataOptions, Action<string?, string?, TraceLevel>)

Configure the database to use the specified a string trace callback.

public static DataOptions UseTraceWith(this DataOptions options, Action<string?, string?, TraceLevel> write)

Parameters

options DataOptions
write Action<string, string, TraceLevel>

Callback, may not be called depending on the trace level.

Returns

DataOptions

The builder instance so calls can be chained.

UseTracing(DataOptions, Action<TraceInfo>)

Configure the database to use the specified callback for logging or tracing.

public static DataOptions UseTracing(this DataOptions options, Action<TraceInfo> onTrace)

Parameters

options DataOptions
onTrace Action<TraceInfo>

Callback, may not be called depending on the trace level.

Returns

DataOptions

The builder instance so calls can be chained.

UseTracing(DataOptions, TraceLevel, Action<TraceInfo>)

Configure the database to use the specified trace level and callback for logging or tracing.

public static DataOptions UseTracing(this DataOptions options, TraceLevel traceLevel, Action<TraceInfo> onTrace)

Parameters

options DataOptions
traceLevel TraceLevel

Trace level to use.

onTrace Action<TraceInfo>

Callback, may not be called depending on the trace level.

Returns

DataOptions

The builder instance so calls can be chained.

UseTransaction(DataOptions, IDataProvider, DbTransaction)

Defines data provider and transaction to use with DataOptions.

public static DataOptions UseTransaction(this DataOptions options, IDataProvider dataProvider, DbTransaction transaction)

Parameters

options DataOptions
dataProvider IDataProvider
transaction DbTransaction

Returns

DataOptions

WithAfterConnectionOpened(ConnectionOptions, Action<DbConnection>, Func<DbConnection, CancellationToken, Task>?)

Sets custom actions, executed after connection opened.

public static ConnectionOptions WithAfterConnectionOpened(this ConnectionOptions options, Action<DbConnection> afterConnectionOpened, Func<DbConnection, CancellationToken, Task>? afterConnectionOpenedAsync = null)

Parameters

options ConnectionOptions
afterConnectionOpened Action<DbConnection>

Action, executed for connection instance after Open() call. Also called after OpenAsync(CancellationToken) call if afterConnectionOpenedAsync action is not provided. Accepts connection instance as parameter.

afterConnectionOpenedAsync Func<DbConnection, CancellationToken, Task>

Action, executed for connection instance from async execution path after OpenAsync(CancellationToken) call. Accepts connection instance as parameter. If this option is not set, afterConnectionOpened synchronous action called. Use this option only if you need to perform async work from action, otherwise afterConnectionOpened is sufficient.

Returns

ConnectionOptions

WithBeforeConnectionOpened(ConnectionOptions, Action<DbConnection>, Func<DbConnection, CancellationToken, Task>?)

Sets custom actions, executed before connection opened.

public static ConnectionOptions WithBeforeConnectionOpened(this ConnectionOptions options, Action<DbConnection> afterConnectionOpening, Func<DbConnection, CancellationToken, Task>? afterConnectionOpeningAsync = null)

Parameters

options ConnectionOptions
afterConnectionOpening Action<DbConnection>

Action, executed before database connection opened. Accepts connection instance as parameter.

afterConnectionOpeningAsync Func<DbConnection, CancellationToken, Task>

Action, executed after database connection opened from async execution path. Accepts connection instance as parameter. If this option is not set, afterConnectionOpening synchronous action called. Use this option only if you need to perform async work from action, otherwise afterConnectionOpening is sufficient.

Returns

ConnectionOptions

WithBulkCopyTimeout(BulkCopyOptions, int?)

Number of seconds for the operation to complete before it times out.

public static BulkCopyOptions WithBulkCopyTimeout(this BulkCopyOptions options, int? bulkCopyTimeout)

Parameters

options BulkCopyOptions
bulkCopyTimeout int?

Returns

BulkCopyOptions

WithBulkCopyType(BulkCopyOptions, BulkCopyType)

Bulk copy mode.

public static BulkCopyOptions WithBulkCopyType(this BulkCopyOptions options, BulkCopyType bulkCopyType)

Parameters

options BulkCopyOptions
bulkCopyType BulkCopyType

Returns

BulkCopyOptions

WithCacheSlidingExpiration(LinqOptions, TimeSpan?)

Specifies timeout when query will be evicted from cache since last execution of query. Default value is 1 hour.

public static LinqOptions WithCacheSlidingExpiration(this LinqOptions options, TimeSpan? cacheSlidingExpiration)

Parameters

options LinqOptions
cacheSlidingExpiration TimeSpan?

Returns

LinqOptions

WithCheckConstraints(BulkCopyOptions, bool?)

Checks constraints while data is being inserted.

public static BulkCopyOptions WithCheckConstraints(this BulkCopyOptions options, bool? checkConstraints)

Parameters

options BulkCopyOptions
checkConstraints bool?

Returns

BulkCopyOptions

WithCoefficient(RetryPolicyOptions, TimeSpan)

The coefficient for the exponential function used to compute the delay between retries, must be nonnegative. Default value: 1 second.

public static RetryPolicyOptions WithCoefficient(this RetryPolicyOptions options, TimeSpan coefficient)

Parameters

options RetryPolicyOptions
coefficient TimeSpan

Returns

RetryPolicyOptions

WithCompareNullsAsValues(LinqOptions, bool)

If set to true nullable fields would be checked for IS NULL in Equal/NotEqual comparisons. This affects: Equal, NotEqual, Not Contains Default value: true.

public static LinqOptions WithCompareNullsAsValues(this LinqOptions options, bool compareNullsAsValues)

Parameters

options LinqOptions
compareNullsAsValues bool

Returns

LinqOptions

Examples

public class MyEntity
{
    public int? Value;
}

db.MyEntity.Where(e => e.Value != 10)

from e1 in db.MyEntity
join e2 in db.MyEntity on e1.Value equals e2.Value
select e1

var filter = new [] {1, 2, 3};
db.MyEntity.Where(e => ! filter.Contains(e.Value))

Would be converted to next queries:

SELECT Value FROM MyEntity WHERE Value IS NULL OR Value != 10

 SELECT e1.Value
 FROM MyEntity e1
 INNER JOIN MyEntity e2 ON e1.Value = e2.Value OR (e1.Value IS NULL AND e2.Value IS NULL)

 SELECT Value FROM MyEntity WHERE Value IS NULL OR NOT Value IN (1, 2, 3)

WithConfigurationString(ConnectionOptions, string?)

Sets ConfigurationString option.

public static ConnectionOptions WithConfigurationString(this ConnectionOptions options, string? configurationString)

Parameters

options ConnectionOptions
configurationString string

Returns

ConnectionOptions

WithConnectionFactory(ConnectionOptions, Func<DataOptions, DbConnection>)

Sets ConnectionFactory option.

public static ConnectionOptions WithConnectionFactory(this ConnectionOptions options, Func<DataOptions, DbConnection> connectionFactory)

Parameters

options ConnectionOptions
connectionFactory Func<DataOptions, DbConnection>

Returns

ConnectionOptions

WithConnectionString(ConnectionOptions, string?)

Sets ConnectionString option.

public static ConnectionOptions WithConnectionString(this ConnectionOptions options, string? connectionString)

Parameters

options ConnectionOptions
connectionString string

Returns

ConnectionOptions

WithDataProvider(ConnectionOptions, IDataProvider?)

Sets DataProvider option.

public static ConnectionOptions WithDataProvider(this ConnectionOptions options, IDataProvider? dataProvider)

Parameters

options ConnectionOptions
dataProvider IDataProvider

Returns

ConnectionOptions

WithDataProviderFactory(ConnectionOptions, Func<ConnectionOptions, IDataProvider>)

Sets DataProviderFactory option.

public static ConnectionOptions WithDataProviderFactory(this ConnectionOptions options, Func<ConnectionOptions, IDataProvider> dataProviderFactory)

Parameters

options ConnectionOptions
dataProviderFactory Func<ConnectionOptions, IDataProvider>

Returns

ConnectionOptions

WithDatabaseName(BulkCopyOptions, string?)

Gets or sets explicit name of target database instead of one, configured for copied entity in mapping schema. See DatabaseName<T>(ITable<T>, string?) method for support information per provider.

public static BulkCopyOptions WithDatabaseName(this BulkCopyOptions options, string? databaseName)

Parameters

options BulkCopyOptions
databaseName string

Returns

BulkCopyOptions

WithDbConnection(ConnectionOptions, DbConnection?)

Sets DbConnection option.

public static ConnectionOptions WithDbConnection(this ConnectionOptions options, DbConnection? connection)

Parameters

options ConnectionOptions
connection DbConnection

Returns

ConnectionOptions

WithDbTransaction(ConnectionOptions, DbTransaction)

Sets DbTransaction option.

public static ConnectionOptions WithDbTransaction(this ConnectionOptions options, DbTransaction transaction)

Parameters

options ConnectionOptions
transaction DbTransaction

Returns

ConnectionOptions

WithDisableQueryCache(LinqOptions, bool)

Used to disable LINQ expressions caching for queries. This cache reduces time, required for query parsing but have several side-effects:

- cached LINQ expressions could contain references to external objects as parameters, which could lead to memory leaks if those objects are not used anymore by other code

- cache access synchronization could lead to bigger latencies than it saves.

Default value: false.

It is not recommended to enable this option as it could lead to severe slowdown. Better approach will be to call ClearCache() method to cleanup cache after queries, that produce severe memory leaks you need to fix.

More details.
public static LinqOptions WithDisableQueryCache(this LinqOptions options, bool disableQueryCache)

Parameters

options LinqOptions
disableQueryCache bool

Returns

LinqOptions

WithDisposeConnection(ConnectionOptions, bool)

Sets DisposeConnection option.

public static ConnectionOptions WithDisposeConnection(this ConnectionOptions options, bool disposeConnection)

Parameters

options ConnectionOptions
disposeConnection bool

Returns

ConnectionOptions

WithDoNotClearOrderBys(LinqOptions, bool)

Controls behavior, when LINQ query chain contains multiple OrderBy<TSource, TKey>(IQueryable<TSource>, Expression<Func<TSource, TKey>>) or OrderByDescending<TSource, TKey>(IQueryable<TSource>, Expression<Func<TSource, TKey>>) calls:

  • if true - non-first OrderBy* call will be treated as ThenBy* call;
  • if false - OrderBy* call will discard sort specifications, added by previous OrderBy* and ThenBy* calls. Default value: false.
public static LinqOptions WithDoNotClearOrderBys(this LinqOptions options, bool doNotClearOrderBys)

Parameters

options LinqOptions
doNotClearOrderBys bool

Returns

LinqOptions

WithEnableConstantExpressionInOrderBy(SqlOptions, bool)

If true, linq2db will allow any constant expressions in ORDER BY clause. Default value: false.

public static SqlOptions WithEnableConstantExpressionInOrderBy(this SqlOptions options, bool enableConstantExpressionInOrderBy)

Parameters

options SqlOptions
enableConstantExpressionInOrderBy bool

Returns

SqlOptions

WithEnableContextSchemaEdit(LinqOptions, bool)

If true, user could add new mappings to context mapping schems (MappingSchema). Otherwise, LinqToDBException will be generated on locked mapping schema edit attempt. It is not recommended to enable this option as it has performance implications. Proper approach is to create single MappingSchema instance once, configure mappings for it and use this MappingSchema instance for all context instances.

public static LinqOptions WithEnableContextSchemaEdit(this LinqOptions options, bool enableContextSchemaEdit)

Parameters

options LinqOptions
enableContextSchemaEdit bool

Returns

LinqOptions

WithExponentialBase(RetryPolicyOptions, double)

The base for the exponential function used to compute the delay between retries, must be positive. Default value: 2.

public static RetryPolicyOptions WithExponentialBase(this RetryPolicyOptions options, double exponentialBase)

Parameters

options RetryPolicyOptions
exponentialBase double

Returns

RetryPolicyOptions

WithFactory(RetryPolicyOptions, Func<DataConnection, IRetryPolicy?>?)

Retry policy factory method, used to create retry policy for new DataConnection instance. If factory method is not set, retry policy is not used. Not set by default.

public static RetryPolicyOptions WithFactory(this RetryPolicyOptions options, Func<DataConnection, IRetryPolicy?>? factory)

Parameters

options RetryPolicyOptions
factory Func<DataConnection, IRetryPolicy>

Returns

RetryPolicyOptions

WithFireTriggers(BulkCopyOptions, bool?)

When specified, causes the server to fire the insert triggers for the rows being inserted into the database.

public static BulkCopyOptions WithFireTriggers(this BulkCopyOptions options, bool? fireTriggers)

Parameters

options BulkCopyOptions
fireTriggers bool?

Returns

BulkCopyOptions

WithGenerateExpressionTest(LinqOptions, bool)

Enables generation of test class for each LINQ query, executed while this option is enabled. This option could be useful for issue reporting, when you need to provide reproducible case. Test file will be placed to linq2db subfolder of temp folder and exact file path will be logged to data connection tracing infrastructure. See TraceSwitch for more details. Default value: false.

public static LinqOptions WithGenerateExpressionTest(this LinqOptions options, bool generateExpressionTest)

Parameters

options LinqOptions
generateExpressionTest bool

Returns

LinqOptions

WithGenerateFinalAliases(SqlOptions, bool)

Indicates whether SQL Builder should generate aliases for final projection. It is not required for correct query processing but simplifies SQL analysis.

Default value: false.

For the query
var query = from child in db.Child
   select new
   {
      TrackId = child.ChildID,
   };
When property is true
SELECT
                                                        [child].[ChildID] as [TrackId]
                                                     FROM
                                                        [Child] [child]
Otherwise alias will be removed
SELECT
   [child].[ChildID]
FROM
   [Child] [child]
public static SqlOptions WithGenerateFinalAliases(this SqlOptions options, bool generateFinalAliases)

Parameters

options SqlOptions
generateFinalAliases bool

Returns

SqlOptions

WithGuardGrouping(LinqOptions, bool)

Controls behavior of LINQ query, which ends with GroupBy call.

public static LinqOptions WithGuardGrouping(this LinqOptions options, bool guardGrouping)

Parameters

options LinqOptions
guardGrouping bool

Returns

LinqOptions

Remarks

WithIgnoreEmptyUpdate(LinqOptions, bool)

Controls behavior of linq2db when there is no updateable fields in Update query:

  • if true - query not executed and Update operation returns 0 as number of affected records;
  • if false - LinqToDBException will be thrown. Default value: false.
public static LinqOptions WithIgnoreEmptyUpdate(LinqOptions options, bool ignoreEmptyUpdate)

Parameters

options LinqOptions
ignoreEmptyUpdate bool

Returns

LinqOptions

WithKeepDistinctOrdered(LinqOptions, bool)

Allows SQL generation to automatically transform

SELECT DISTINCT value FROM Table ORDER BY date

Into GROUP BY equivalent if syntax is not supported Default value: true.

public static LinqOptions WithKeepDistinctOrdered(this LinqOptions options, bool keepDistinctOrdered)

Parameters

options LinqOptions
keepDistinctOrdered bool

Returns

LinqOptions

WithKeepIdentity(BulkCopyOptions, bool?)

If this option set to true, bulk copy will use values of columns, marked with IsIdentity flag. SkipOnInsert flag in this case will be ignored. Otherwise, those columns will be skipped and values will be generated by server. Not compatible with RowByRow mode.

public static BulkCopyOptions WithKeepIdentity(this BulkCopyOptions options, bool? keepIdentity)

Parameters

options BulkCopyOptions
keepIdentity bool?

Returns

BulkCopyOptions

WithKeepNulls(BulkCopyOptions, bool?)

Preserves null values in the destination table regardless of the settings for default values.

public static BulkCopyOptions WithKeepNulls(this BulkCopyOptions options, bool? keepNulls)

Parameters

options BulkCopyOptions
keepNulls bool?

Returns

BulkCopyOptions

WithMappingSchema(ConnectionOptions, MappingSchema)

Sets MappingSchema option.

public static ConnectionOptions WithMappingSchema(this ConnectionOptions options, MappingSchema mappingSchema)

Parameters

options ConnectionOptions
mappingSchema MappingSchema

Returns

ConnectionOptions

WithMaxBatchSize(BulkCopyOptions, int?)

Number of rows in each batch. At the end of each batch, the rows in the batch are sent to the server. Returns an integer value or zero if no value has been set.

public static BulkCopyOptions WithMaxBatchSize(this BulkCopyOptions options, int? maxBatchSize)

Parameters

options BulkCopyOptions
maxBatchSize int?

Returns

BulkCopyOptions

WithMaxDegreeOfParallelism(BulkCopyOptions, int?)

Implemented only by ClickHouse.Client provider. Defines number of connections, used for parallel insert in ProviderSpecific mode.

public static BulkCopyOptions WithMaxDegreeOfParallelism(this BulkCopyOptions options, int? maxDegreeOfParallelism)

Parameters

options BulkCopyOptions
maxDegreeOfParallelism int?

Returns

BulkCopyOptions

WithMaxDelay(RetryPolicyOptions, TimeSpan)

The maximum time delay between retries, must be nonnegative. Default value: 30 seconds.

public static RetryPolicyOptions WithMaxDelay(this RetryPolicyOptions options, TimeSpan maxDelay)

Parameters

options RetryPolicyOptions
maxDelay TimeSpan

Returns

RetryPolicyOptions

WithMaxParametersForBatch(BulkCopyOptions, int?)

If set, will override the Maximum parameters per batch statement from MaxParameters.

public static BulkCopyOptions WithMaxParametersForBatch(this BulkCopyOptions options, int? maxParametersForBatch)

Parameters

options BulkCopyOptions
maxParametersForBatch int?

Returns

BulkCopyOptions

WithMaxRetryCount(RetryPolicyOptions, int)

The number of retry attempts. Default value: 5.

public static RetryPolicyOptions WithMaxRetryCount(this RetryPolicyOptions options, int maxRetryCount)

Parameters

options RetryPolicyOptions
maxRetryCount int

Returns

RetryPolicyOptions

WithNotifyAfter(BulkCopyOptions, int)

Gets or sets counter after how many copied records RowsCopiedCallback should be called. E.g. if you set it to 10, callback will be called after each 10 copied records. To disable callback, set this option to 0 (default value).

public static BulkCopyOptions WithNotifyAfter(this BulkCopyOptions options, int notifyAfter)

Parameters

options BulkCopyOptions
notifyAfter int

Returns

BulkCopyOptions

WithOnEntityDescriptorCreated(ConnectionOptions, Action<MappingSchema, IEntityChangeDescriptor>)

Sets OnEntityDescriptorCreated option.

public static ConnectionOptions WithOnEntityDescriptorCreated(this ConnectionOptions options, Action<MappingSchema, IEntityChangeDescriptor> onEntityDescriptorCreated)

Parameters

options ConnectionOptions
onEntityDescriptorCreated Action<MappingSchema, IEntityChangeDescriptor>

Returns

ConnectionOptions

WithOnTrace(QueryTraceOptions, Action<TraceInfo>)

Configure the database to use the specified callback for logging or tracing.

public static QueryTraceOptions WithOnTrace(this QueryTraceOptions options, Action<TraceInfo> onTrace)

Parameters

options QueryTraceOptions
onTrace Action<TraceInfo>

Callback, may not be called depending on the trace level.

Returns

QueryTraceOptions

The builder instance so calls can be chained.

WithOptimizeJoins(LinqOptions, bool)

If enabled, linq2db will try to reduce number of generated SQL JOINs for LINQ query. Attempted optimizations:

  • removes duplicate joins by unique target table key;
  • removes self-joins by unique key;
  • removes left joins if joined table is not used in query. Default value: true.
public static LinqOptions WithOptimizeJoins(this LinqOptions options, bool optimizeJoins)

Parameters

options LinqOptions
optimizeJoins bool

Returns

LinqOptions

WithParameterizeTakeSkip(LinqOptions, bool)

Enables Take/Skip parameterization. Default value: true.

public static LinqOptions WithParameterizeTakeSkip(this LinqOptions options, bool parameterizeTakeSkip)

Parameters

options LinqOptions
parameterizeTakeSkip bool

Returns

LinqOptions

WithPreferApply(LinqOptions, bool)

Used to generate CROSS APPLY or OUTER APPLY if possible. Default value: true.

public static LinqOptions WithPreferApply(this LinqOptions options, bool preferApply)

Parameters

options LinqOptions
preferApply bool

Returns

LinqOptions

WithPreferExistsForScalar(LinqOptions, bool)

Depending on this option linq2db generates different SQL for sequence.Contains(value).
true - EXISTS (SELECT * FROM sequence WHERE sequence.key = value).
false - value IN (SELECT sequence.key FROM sequence).
Default value: false.

public static LinqOptions WithPreferExistsForScalar(this LinqOptions options, bool preferExistsForScalar)

Parameters

options LinqOptions
preferExistsForScalar bool

Returns

LinqOptions

WithPreloadGroups(LinqOptions, bool)

Controls how group data for LINQ queries ended with GroupBy will be loaded:

  • if true - group data will be loaded together with main query, resulting in 1 + N queries, where N - number of groups;
  • if false - group data will be loaded when you call enumerator for specific group IGrouping<TKey, TElement>. Default value: false.
public static LinqOptions WithPreloadGroups(this LinqOptions options, bool preloadGroups)

Parameters

options LinqOptions
preloadGroups bool

Returns

LinqOptions

WithProviderName(ConnectionOptions, string)

Sets ProviderName option.

public static ConnectionOptions WithProviderName(this ConnectionOptions options, string providerName)

Parameters

options ConnectionOptions
providerName string

Returns

ConnectionOptions

WithRandomFactor(RetryPolicyOptions, double)

The maximum random factor, must not be lesser than 1. Default value: 1.1.

public static RetryPolicyOptions WithRandomFactor(this RetryPolicyOptions options, double randomFactor)

Parameters

options RetryPolicyOptions
randomFactor double

Returns

RetryPolicyOptions

WithRetryPolicy(RetryPolicyOptions, IRetryPolicy)

Uses retry policy

public static RetryPolicyOptions WithRetryPolicy(this RetryPolicyOptions options, IRetryPolicy retryPolicy)

Parameters

options RetryPolicyOptions
retryPolicy IRetryPolicy

Returns

RetryPolicyOptions

WithRowsCopiedCallback(BulkCopyOptions, Action<BulkCopyRowsCopied>?)

Gets or sets callback method that will be called by BulkCopy operation after each NotifyAfter rows copied. This callback will not be used if NotifyAfter set to 0.

public static BulkCopyOptions WithRowsCopiedCallback(this BulkCopyOptions options, Action<BulkCopyRowsCopied>? rowsCopiedCallback)

Parameters

options BulkCopyOptions
rowsCopiedCallback Action<BulkCopyRowsCopied>

Returns

BulkCopyOptions

WithSchemaName(BulkCopyOptions, string?)

Gets or sets explicit name of target schema/owner instead of one, configured for copied entity in mapping schema. See SchemaName<T>(ITable<T>, string?) method for support information per provider.

public static BulkCopyOptions WithSchemaName(this BulkCopyOptions options, string? schemaName)

Parameters

options BulkCopyOptions
schemaName string

Returns

BulkCopyOptions

WithServerName(BulkCopyOptions, string?)

Gets or sets explicit name of target server instead of one, configured for copied entity in mapping schema. See ServerName<T>(ITable<T>, string?) method for support information per provider. Also note that it is not supported by provider-specific insert method.

public static BulkCopyOptions WithServerName(this BulkCopyOptions options, string? serverName)

Parameters

options BulkCopyOptions
serverName string

Returns

BulkCopyOptions

WithTableLock(BulkCopyOptions, bool?)

Obtains a bulk update lock for the duration of the bulk copy operation.

public static BulkCopyOptions WithTableLock(this BulkCopyOptions options, bool? tableLock)

Parameters

options BulkCopyOptions
tableLock bool?

Returns

BulkCopyOptions

WithTableName(BulkCopyOptions, string?)

Gets or sets explicit name of target table instead of one, configured for copied entity in mapping schema.

public static BulkCopyOptions WithTableName(this BulkCopyOptions options, string? tableName)

Parameters

options BulkCopyOptions
tableName string

Returns

BulkCopyOptions

WithTableOptions(BulkCopyOptions, TableOptions)

Gets or sets TableOptions flags overrides instead of configured for copied entity in mapping schema. See IsTemporary<T>(ITable<T>, bool) method for support information per provider.

public static BulkCopyOptions WithTableOptions(this BulkCopyOptions options, TableOptions tableOptions)

Parameters

options BulkCopyOptions
tableOptions TableOptions

Returns

BulkCopyOptions

WithTraceLevel(QueryTraceOptions, TraceLevel)

Configure the database to use specified trace level.

public static QueryTraceOptions WithTraceLevel(this QueryTraceOptions options, TraceLevel traceLevel)

Parameters

options QueryTraceOptions
traceLevel TraceLevel

Returns

QueryTraceOptions

The builder instance so calls can be chained.

WithTraceMapperExpression(LinqOptions, bool)

Enables logging of generated mapping expression to data connection tracing infrastructure. See TraceSwitch for more details. Default value: false.

public static LinqOptions WithTraceMapperExpression(this LinqOptions options, bool traceMapperExpression)

Parameters

options LinqOptions
traceMapperExpression bool

Returns

LinqOptions

WithUseInternalTransaction(BulkCopyOptions, bool?)

When specified, each batch of the bulk-copy operation will occur within a transaction.

public static BulkCopyOptions WithUseInternalTransaction(this BulkCopyOptions options, bool? useInternalTransaction)

Parameters

options BulkCopyOptions
useInternalTransaction bool?

Returns

BulkCopyOptions

WithUseParameters(BulkCopyOptions, bool)

Gets or sets whether to Always use Parameters for MultipleRowsCopy. Default is false. If True, provider's override for MaxParameters will be used to determine the maximum number of rows per insert, Unless overridden by MaxParametersForBatch.

public static BulkCopyOptions WithUseParameters(this BulkCopyOptions options, bool useParameters)

Parameters

options BulkCopyOptions
useParameters bool

Returns

BulkCopyOptions

WithWithoutSession(BulkCopyOptions, bool)

Implemented only by ClickHouse.Client provider. When set, provider-specific bulk copy will use session-less connection even if called over connection with session. Note that session-less connections cannot be used with session-bound functionality like temporary tables.

public static BulkCopyOptions WithWithoutSession(this BulkCopyOptions options, bool withoutSession)

Parameters

options BulkCopyOptions
withoutSession bool

Returns

BulkCopyOptions

WithWriteTrace(QueryTraceOptions, Action<string?, string?, TraceLevel>)

Configure the database to use the specified a string trace callback.

public static QueryTraceOptions WithWriteTrace(this QueryTraceOptions options, Action<string?, string?, TraceLevel> write)

Parameters

options QueryTraceOptions
write Action<string, string, TraceLevel>

Callback, may not be called depending on the trace level.

Returns

QueryTraceOptions

The builder instance so calls can be chained.