Link Search Menu Expand Document

IDbSetting


This interface is used to mark a class to be a database setting object. It allows you to control the behavior of the library on a specific RDBMS data provider based on the value you provided on the properties this class.

Properties

Below is the list of properties.

NameDescription
AreTableHintsSupportedGets the value that indicates whether the table hints are supported.
ClosingQuoteGets the character used for closing quote.
AverageableTypeGets the default averageable .NET CLR types for the database.
DefaultSchemaGets the default schema of the database.
IsAffectedRowsSupportedGets a value that indicates whether the current DB Provider supports returning the number of affected rows from the execution of a non-query command.
IsDirectionSupportedGets a value that indicates whether setting the value of DbParameter.Direction object is supported.
IsExecuteReaderDisposableGets a value that indicates whether the DbCommand object must be disposed after calling the DbCommand.ExecuteReader() method.
IsMultiStatementExecutableGets a value whether the multiple statement execution is supported.
IsPreparableGets a value that indicates whether the current DB Provider supports the DbCommand.Prepare() calls.
IsTransactionSupportedGets a value that indicates whether the current DB Provider supports the transaction objects.
IsUseUpsertGets a value that indicates whether the Insert/Update operation will be used for Merge operation.
MultiStatementSeparatorGets the string used to join the individual command texts generated by the QueryMultiple and QueryMultipleAsync operations into a single command text.
OpeningQuoteGets the character used for opening quote.
ParameterPrefixGets the character used for the database command parameter prefixing.
SqlTextParameterPrefixGets the character used for prefixing a parameter when it is embedded within a raw/text SQL statement, as opposed to when it is bound as a DbParameter object.

How to Implement?

You have to manually create a class that implements this interface.

public class MyCustomSqlServerDbSetting : IDbSetting
{
    public bool AreTableHintsSupported { get; set; } = true;
    public string ClosingQuote { get; set; } = "]";
    public Type AverageableType { get; set; } = typeof(double);
    public string DefaultSchema { get; set; } = "dbo";
    public bool IsAffectedRowsSupported { get; set; } = true;
    public bool IsDirectionSupported { get; set; } = true;
    public bool IsExecuteReaderDisposable { get; set; } = true;
    public bool IsMultiStatementExecutable { get; set; } = true;
    public bool IsPreparable { get; set; } = true;
    public bool IsTransactionSupported { get; set; } = true;
    public bool IsUseUpsert { get; set; } = false;
    public string MultiStatementSeparator { get; set; } = ";";
    public string OpeningQuote { get; set; } = "[";
    public string ParameterPrefix { get; set; } = "@";
    public string SqlTextParameterPrefix { get; set; } = "@";
}

Please see the more detailed implementations at Database Setting page.

GetHashCode

You have to override the implementation of the GetHashCode() based on the combinations of the properties.

The reason to this, the library is using the equality based on the generated hashcode. Failure to comply may trigger a performance problem in your application.

We recommend to instead use the BaseDbSetting class when implementing a customized database setting.

Usability

Once the class has been implemented, you have to call the DbSettingMapper class for mappings (per RDBMS data provider).

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