Link Search Menu Expand Document

BaseDbSetting


This class is the base class of all IDbSetting-based classes.

Use-Cases

Use this class instead of the IDbSetting interface when overriding default database settings.

How to Implement?

Create a class that inherits this class and set the properties in the constructor.

public sealed class MyCustomSqlServerDbSetting : BaseDbSetting
{
    public MyCustomSqlServerDbSetting()
        : base()
    {
        AreTableHintsSupported = true;
        AverageableType = typeof(double);
        ClosingQuote = "]";
        DefaultSchema = "dbo";
        IsAffectedRowsSupported = true;
        IsDirectionSupported = true;
        IsExecuteReaderDisposable = true;
        IsInsertAllBatchable = null;
        IsMultiStatementExecutable = true;
        IsPreparable = true;
        IsTransactionSupported = true;
        IsUseUpsert = false;
        MaxParameterCount = 2098;
        MultiStatementSeparator = ";";
        OpeningQuote = "[";
        ParameterPrefix = "@";
        RequiresDbTypeBeforeValue = false;
        SchemaSeparator = ".";
        SkipsUnreferencedParameters = false;
        SqlTextParameterPrefix = "@";
    }
}

The MaxParameterCount property caps the number of parameters/members the provider allows in a single generated command text — most directly, the number of values a single WHERE column IN (...) clause can hold. Operations that batch a large key list into that shape (e.g. DeleteAll(keys)) split it into chunks no larger than this value before generating each chunk’s command text. It defaults to 2098 (SQL Server’s ~2100 parameter ceiling, minus a small safety margin); override it for a provider with a lower hard limit (e.g. Firebird’s DSQL parser rejects an IN (...) list past 1500 members with “Implementation limit exceeded”).

The MultiStatementSeparator property is the string used to join the individual command texts generated by the QueryMultiple and QueryMultipleAsync operations into a single command text. It defaults to ";". Override it for providers whose driver rejects a trailing statement terminator on an otherwise-standalone command, by giving it the provider’s own inter-statement separator instead.

The IsInsertAllBatchable property overrides IsMultiStatementExecutable specifically for whether InsertAll can batch more than one row into a single statement — a genuine multi-row VALUES (...), (...), ... list, not multiple ;-separated statements. It defaults to null, which falls back to IsMultiStatementExecutable. Set it explicitly when a provider can support one but not the other: Vertica, for example, sets IsMultiStatementExecutable = false (its driver refuses a compound ;-separated statement once it carries a parameter) but IsInsertAllBatchable = true, since a single INSERT ... VALUES (...), (...) is still just one statement.

The RequiresDbTypeBeforeValue property controls the order DbParameter.DbType and DbParameter.Value are assigned in. It defaults to false (Value first); set it to true for a provider whose driver lazily initializes internal parameter state inside the DbType setter and throws if Value is assigned first on a parameter fresh off DbCommand.CreateParameter() — when true, DbType is assigned before Value, inferred from the value’s CLR type if not explicitly given.

The SkipsUnreferencedParameters property controls whether a bound parameter with no corresponding placeholder in the generated command text is skipped rather than bound. It defaults to false. Set it to true for a provider that strictly validates every bound parameter is actually referenced — a null-valued equality filter (e.g. WHERE "Id" = @Id with a null value) is rendered by QueryField as the literal "Id" IS NULL with no @Id placeholder, so a strict provider would otherwise reject the whole command over the now-unreferenced parameter.

This class already implements GetHashCode(), so no override is required.

Usability

Use the DbSettingMapper class to map the setting to a specific RDBMS provider.

DbSettingMapper.Add(typeof(SqlConnection), new MyCustomSqlServerDbSetting(), true);