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
MaxParameterCountproperty caps the number of parameters/members the provider allows in a single generated command text — most directly, the number of values a singleWHERE 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 to2098(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 anIN (...)list past 1500 members with “Implementation limit exceeded”).
The
MultiStatementSeparatorproperty is the string used to join the individual command texts generated by the QueryMultiple andQueryMultipleAsyncoperations 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
IsInsertAllBatchableproperty overridesIsMultiStatementExecutablespecifically for whether InsertAll can batch more than one row into a single statement — a genuine multi-rowVALUES (...), (...), ...list, not multiple;-separated statements. It defaults tonull, which falls back toIsMultiStatementExecutable. Set it explicitly when a provider can support one but not the other: Vertica, for example, setsIsMultiStatementExecutable = false(its driver refuses a compound;-separated statement once it carries a parameter) butIsInsertAllBatchable = true, since a singleINSERT ... VALUES (...), (...)is still just one statement.
The
RequiresDbTypeBeforeValueproperty controls the orderDbParameter.DbTypeandDbParameter.Valueare assigned in. It defaults tofalse(Valuefirst); set it totruefor a provider whose driver lazily initializes internal parameter state inside theDbTypesetter and throws ifValueis assigned first on a parameter fresh offDbCommand.CreateParameter()— whentrue,DbTypeis assigned beforeValue, inferred from the value’s CLR type if not explicitly given.
The
SkipsUnreferencedParametersproperty controls whether a bound parameter with no corresponding placeholder in the generated command text is skipped rather than bound. It defaults tofalse. Set it totruefor a provider that strictly validates every bound parameter is actually referenced — a null-valued equality filter (e.g.WHERE "Id" = @Idwith anullvalue) is rendered by QueryField as the literal"Id" IS NULLwith no@Idplaceholder, so a strict provider would otherwise reject the whole command over the now-unreferenced parameter.
The
AreIndexNamesUniquePerSchemaproperty indicates whether the name of an index must be unique in the whole schema (or database), instead of only in its table. It defaults tofalse. Set it totruefor 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
Providerproperty 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 tonull; set it in the constructor of your derived class. When it is set, it is included in the computed hash code.
The
IsSchemaSupportedproperty indicates whether the provider supports the schemas (i.e.:dboorpublic) that own the tables of a database. It defaults totrue. Set it tofalsefor 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);