BaseDbSetting

A base class for all the database setting classes.

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()
    {
        AreIndexNamesUniquePerSchema = false;
        AreTableHintsSupported = true;
        AverageableType = typeof(double);
        ClosingQuote = "]";
        DefaultSchema = "dbo";
        IsAffectedRowsSupported = true;
        IsDirectionSupported = true;
        IsExecuteReaderDisposable = true;
        IsInsertAllBatchable = null;
        IsMultiStatementExecutable = true;
        IsPreparable = true;
        IsSchemaSupported = true;
        IsTransactionSupported = true;
        IsUseUpsert = false;
        MaxParameterCount = 2098;
        MultiStatementSeparator = ";";
        OpeningQuote = "[";
        ParameterPrefix = "@";
        Provider = "SqlServer";
        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.

The AreIndexNamesUniquePerSchema property indicates whether the name of an index must be unique in the whole schema (or database), instead of only in its table. It defaults to false. Set it to true for a provider such as PostgreSQL, Oracle, Firebird or SQLite, where two tables can not own indexes of the same name, so the name alone identifies the index. It is included in the computed hash code.

The Provider property holds the name of the DB provider that the setting is for (i.e.: SqlServer, PostgreSql, MySql, SQLite). It is the same name that the schema readers give to the tables and to the columns that they read, so the objects of a database can tell which provider they are from. It defaults to null; set it in the constructor of your derived class. When it is set, it is included in the computed hash code.

The IsSchemaSupported property indicates whether the provider supports the schemas (i.e.: dbo or public) that own the tables of a database. It defaults to true. Set it to false for a provider where a table is only identified by its name (and by the database, if the provider has one), such as MySQL, MariaDB, SQLite and Firebird.

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);