ISqlDialect

Ecng.Data

Contract for a database-specific SQL dialect. Implementations are usually derived from SqlDialectBase, which already provides reasonable defaults for everything that is not strictly dialect-specific — concrete dialects only override what differs (quoting, type mapping, pagination shape, identity bookkeeping). This interface intentionally holds signatures only; default bodies live in SqlDialectBase so we never have to keep two copies of the same implementation in sync.

属性

BatchSeparator
public string BatchSeparator { get; }
value = iSqlDialect.BatchSeparator

Batch separator (e.g. GO for SQL Server). Empty when no separation is needed.

BooleanCastSqlType
public string BooleanCastSqlType { get; }
value = iSqlDialect.BooleanCastSqlType

SQL type name to cast a boolean expression to when materialising EXISTS(...) projections (e.g. bit on SQL Server). Return if the dialect represents booleans natively and no cast is needed (e.g. PostgreSQL).

CanAlterColumn
public bool CanAlterColumn { get; }
value = iSqlDialect.CanAlterColumn

Whether an existing column's type or nullability can be changed in place. SQLite cannot: such a change means rebuilding the table.

CanAlterColumnWithDependents
public bool CanAlterColumnWithDependents { get; }
value = iSqlDialect.CanAlterColumnWithDependents

Whether ALTER COLUMN can change a column that an index, a primary key or a foreign key depends on. SQL Server cannot: those have to be dropped before and recreated after.

ConcatOperator
public string ConcatOperator { get; }
value = iSqlDialect.ConcatOperator

SQL string concatenation operator.

DecimalComparisonCastSqlType
public string DecimalComparisonCastSqlType { get; }
value = iSqlDialect.DecimalComparisonCastSqlType

SQL type name used to cast decimal operands before comparisons when the dialect stores decimals in a non-numeric affinity. Return when no comparison cast is required.

EmptyBinaryLiteral
public string EmptyBinaryLiteral { get; }
value = iSqlDialect.EmptyBinaryLiteral

SQL literal for an empty binary value (e.g. 0x for SQL Server, X'' for the SQL standard, an empty bytea for PostgreSQL).

FalseLiteral
public string FalseLiteral { get; }
value = iSqlDialect.FalseLiteral

SQL literal for boolean false.

IsNullFunction
public string IsNullFunction { get; }
value = iSqlDialect.IsNullFunction

Function name for null-coalescing.

KeepsDecimalDigits
public bool KeepsDecimalDigits { get; }
value = iSqlDialect.KeepsDecimalDigits

Whether a decimal column keeps a declared precision and scale. A dialect that stores decimals as text keeps neither, so there is nothing to compare a declaration against.

LenFunction
public string LenFunction { get; }
value = iSqlDialect.LenFunction

Function name for string length.

MaxParameters
public int MaxParameters { get; }
value = iSqlDialect.MaxParameters

Maximum number of parameters allowed in a single statement. SQL Server: 2100, SQLite: 999, PostgreSQL: 65535, MySQL: 65535.

ParameterPrefix
public string ParameterPrefix { get; }
value = iSqlDialect.ParameterPrefix

Parameter prefix (e.g. @ for SQL Server, $ for PostgreSQL).

SupportsAddForeignKeyViaAlter
public bool SupportsAddForeignKeyViaAlter { get; }
value = iSqlDialect.SupportsAddForeignKeyViaAlter

True when this dialect can add a foreign key to an existing table via String). When false (SQLite), a foreign key can only be declared inline inside CREATE TABLE, so the migrator keeps new-table FKs inline and creates the referenced tables first.

SupportsInsertReturning
public bool SupportsInsertReturning { get; }
value = iSqlDialect.SupportsInsertReturning

True when this dialect can return a server-generated identity in the same statement via String); callers use it to choose between a single-statement INSERT…RETURNING and a two-statement INSERT + SELECT identity batch.

TrueLiteral
public string TrueLiteral { get; }
value = iSqlDialect.TrueLiteral

SQL literal for boolean true.

UnicodePrefix
public string UnicodePrefix { get; }
value = iSqlDialect.UnicodePrefix

Unicode string-literal prefix (e.g. N for SQL Server).

方法

AppendAddColumn
public void AppendAddColumn(StringBuilder sb, string tableName, string columnName, string columnDef)
iSqlDialect.AppendAddColumn(sb, tableName, columnName, columnDef)

Appends ALTER TABLE ADD COLUMN.

AppendAddForeignKey
public void AppendAddForeignKey(StringBuilder sb, string tableName, string columnName, string refTableName, string refColumnName)
iSqlDialect.AppendAddForeignKey(sb, tableName, columnName, refTableName, refColumnName)

Appends an ALTER TABLE ADD CONSTRAINT for a new foreign key.

AppendAlterColumn
public void AppendAlterColumn(StringBuilder sb, string tableName, string columnName, Type clrType, bool isNullable, int maxLength, int precision, int scale, DbColumnInfo live)
iSqlDialect.AppendAlterColumn(sb, tableName, columnName, clrType, isNullable, maxLength, precision, scale, live)

Appends ALTER TABLE ALTER COLUMN that gives a column the declared type and nullability.

sb
Where the statement goes.
tableName
The table.
columnName
The column.
clrType
The property type the column holds.
isNullable
Whether the column should allow NULLs.
maxLength
The declared length, 0 for the default.
precision
The declared precision, 0 for the default.
scale
The declared scale.
live
The column as the database holds it, or null for a column this script has just added; a dialect uses it to keep what the declaration does not decide, and to convert the stored values.
AppendAlterNullability
public void AppendAlterNullability(StringBuilder sb, string tableName, string columnName, bool isNullable, DbColumnInfo live)
iSqlDialect.AppendAlterNullability(sb, tableName, columnName, isNullable, live)

Makes a column nullable or not, leaving its type as the database holds it.

sb
Where the statement goes.
tableName
The table.
columnName
The column.
isNullable
Whether the column should allow NULLs.
live
The column as the database holds it.
AppendCreateIndex
public void AppendCreateIndex(StringBuilder sb, string indexName, string tableName, string columnName, bool unique)
iSqlDialect.AppendCreateIndex(sb, indexName, tableName, columnName, unique)

Appends a CREATE INDEX (or CREATE UNIQUE INDEX) on a single column.

AppendCreateTable
public void AppendCreateTable(StringBuilder sb, string tableName, string columnDefs)
iSqlDialect.AppendCreateTable(sb, tableName, columnDefs)

Appends CREATE TABLE [IF NOT EXISTS] statement.

AppendDateAdd
public void AppendDateAdd(StringBuilder sb, string part, string amountSql, string sourceSql)
iSqlDialect.AppendDateAdd(sb, part, amountSql, sourceSql)

Appends a DATEADD-style expression.

AppendDateDiff
public void AppendDateDiff(StringBuilder sb, string part, string startSql, string endSql)
iSqlDialect.AppendDateDiff(sb, part, startSql, endSql)

Appends a DATEDIFF-style expression computing minus , expressed in units.

sb
Target builder.
part
Unit of the result: year, month, week, day, hour, minute, second or millisecond.
startSql
SQL of the start date.
endSql
SQL of the end date.
AppendDatePartClose
public void AppendDatePartClose(StringBuilder sb)
iSqlDialect.AppendDatePartClose(sb)

Closes a date-part extraction expression opened by String).

AppendDatePartOpen
public void AppendDatePartOpen(StringBuilder sb, string part)
iSqlDialect.AppendDatePartOpen(sb, part)

Opens a date-part extraction expression (closed by StringBuilder)).

AppendDecimalModulo
public void AppendDecimalModulo(StringBuilder sb, string dividendSql, string divisorSql)
iSqlDialect.AppendDecimalModulo(sb, dividendSql, divisorSql)

Appends the remainder of dividing one decimal value by another, fraction included and with the sign of the dividend, as the C# % operator gives it.

sb
Target builder.
dividendSql
SQL of the dividend.
divisorSql
SQL of the divisor.
AppendDeleteBy
public void AppendDeleteBy(StringBuilder sb, string tableName, string[] whereColumns)
iSqlDialect.AppendDeleteBy(sb, tableName, whereColumns)

Appends a DELETE … WHERE statement.

AppendDropColumn
public void AppendDropColumn(StringBuilder sb, string tableName, string columnName)
iSqlDialect.AppendDropColumn(sb, tableName, columnName)

Appends ALTER TABLE DROP COLUMN.

AppendDropForeignKey
public void AppendDropForeignKey(StringBuilder sb, string tableName, string constraintName)
iSqlDialect.AppendDropForeignKey(sb, tableName, constraintName)

Appends an ALTER TABLE DROP CONSTRAINT for an existing foreign key.

AppendDropIndex
public void AppendDropIndex(StringBuilder sb, string tableName, string indexName)
iSqlDialect.AppendDropIndex(sb, tableName, indexName)

Appends DROP INDEX.

AppendDropTable
public void AppendDropTable(StringBuilder sb, string tableName)
iSqlDialect.AppendDropTable(sb, tableName)

Appends DROP TABLE [IF EXISTS] statement.

AppendFallbackOrderBy
public void AppendFallbackOrderBy(StringBuilder sb)
iSqlDialect.AppendFallbackOrderBy(sb)

Appends a fallback ORDER BY clause when there is neither explicit ordering nor an identity column. SQL Server requires ORDER BY for OFFSET/FETCH; other dialects may emit a deterministic shim or nothing at all.

AppendGreatest
public void AppendGreatest(StringBuilder sb, string leftSql, string rightSql)
iSqlDialect.AppendGreatest(sb, leftSql, rightSql)

Appends the larger of two values, the way Decimal) picks it: a scalar function of two arguments, not the MAX aggregate.

sb
Target builder.
leftSql
SQL of the first value.
rightSql
SQL of the second value.
AppendInsertReturningClause
public void AppendInsertReturningClause(StringBuilder sb, string idColumn)
iSqlDialect.AppendInsertReturningClause(sb, idColumn)

Appends a dialect-specific RETURNING clause to an INSERT, scoped to the given identity column. PostgreSQL emits RETURNING "Id"; SQL Server and SQLite have other identity-read mechanisms and emit nothing here.

AppendLeast
public void AppendLeast(StringBuilder sb, string leftSql, string rightSql)
iSqlDialect.AppendLeast(sb, leftSql, rightSql)

Appends the smaller of two values, the way Decimal) picks it: a scalar function of two arguments, not the MIN aggregate.

sb
Target builder.
leftSql
SQL of the first value.
rightSql
SQL of the second value.
AppendPagination
public void AppendPagination(StringBuilder sb, long? skip, long? take, bool hasOrderBy)
iSqlDialect.AppendPagination(sb, skip, take, hasOrderBy)

Appends literal pagination (LIMIT/OFFSET or OFFSET/FETCH) with values.

AppendPaginationParams
public void AppendPaginationParams(StringBuilder sb, string skipParamExpr, string takeParamExpr)
iSqlDialect.AppendPaginationParams(sb, skipParamExpr, takeParamExpr)

Appends parameterised pagination with already-prefixed parameter expressions (e.g. @skip, @take).

AppendRound
public void AppendRound(StringBuilder sb, string valueSql, string digitsSql, MidpointRounding mode)
iSqlDialect.AppendRound(sb, valueSql, digitsSql, mode)

Appends an expression that rounds a value the way MidpointRounding) does with the given mode.

sb
Target builder.
valueSql
SQL of the value.
digitsSql
SQL of the number of fractional digits to keep, or to round to a whole number.
mode
How the value is rounded; ToZero truncates.
AppendSetCompression
public void AppendSetCompression(StringBuilder builder, string tableName, DataCompressions compression)
iSqlDialect.AppendSetCompression(builder, tableName, compression)

Writes the statement that repacks a table.

builder
Where the statement is written.
tableName
Table to repack.
compression
The packing to apply.
AppendTrimClose
public void AppendTrimClose(StringBuilder sb)
iSqlDialect.AppendTrimClose(sb)

Closes a TRIM expression opened by StringBuilder).

AppendTrimOpen
public void AppendTrimOpen(StringBuilder sb)
iSqlDialect.AppendTrimOpen(sb)

Opens a TRIM expression (closed by StringBuilder)).

AppendUpdateBy
public void AppendUpdateBy(StringBuilder sb, string tableName, string[] setColumns, string[] whereColumns)
iSqlDialect.AppendUpdateBy(sb, tableName, setColumns, whereColumns)

Appends an UPDATE … SET … WHERE statement.

AppendUpdateWhereNull
public void AppendUpdateWhereNull(StringBuilder sb, string tableName, string columnName, string defaultLiteral)
iSqlDialect.AppendUpdateWhereNull(sb, tableName, columnName, defaultLiteral)

Appends UPDATE … SET column = literal WHERE column IS NULL — used during migrations to fill default values before altering nullability.

AppendUpsert
public void AppendUpsert(StringBuilder sb, string tableName, string[] allColumns, string[] keyColumns)
iSqlDialect.AppendUpsert(sb, tableName, allColumns, keyColumns)

Appends a UPSERT statement (MERGE on SQL Server, INSERT … ON CONFLICT on PostgreSQL/SQLite).

ConvertFromDbValue
public object ConvertFromDbValue(object value, Type targetType)
result = iSqlDialect.ConvertFromDbValue(value, targetType)

Converts a database value to the requested CLR target type.

ConvertToDbValue
public object ConvertToDbValue(object value, Type clrType)
result = iSqlDialect.ConvertToDbValue(value, clrType)

Converts a CLR value to the form a database driver expects.

FormatSkip
public string FormatSkip(string skip)
result = iSqlDialect.FormatSkip(skip)

Renders a SKIP/OFFSET clause from a parameter expression.

FormatTake
public string FormatTake(string take)
result = iSqlDialect.FormatTake(take)

Renders a TAKE/FETCH clause from a parameter expression.

GetColumnDefinition
public string GetColumnDefinition(Type clrType, bool isNullable, int maxLength, int precision, int scale)
result = iSqlDialect.GetColumnDefinition(clrType, isNullable, maxLength, precision, scale)

Full column definition: SQL type + NULL/NOT NULL.

GetColumnTypeName
public string GetColumnTypeName(Type clrType, int maxLength, int precision, int scale)
result = iSqlDialect.GetColumnTypeName(clrType, maxLength, precision, scale)

The SQL type a column is created with: the type name together with its length, precision or scale. A decimal that declares only a scale gets DefaultDecimalPrecision; one that declares a precision keeps its scale as declared, zero included.

GetDefaultLiteral
public string GetDefaultLiteral(Type clrType)
result = iSqlDialect.GetDefaultLiteral(clrType)

Returns a SQL literal representing the default value for the given CLR type. Used during migrations to backfill NOT NULL columns.

GetForeignKeyConstraint
public string GetForeignKeyConstraint(string tableName, string columnName, string refTableName, string refColumnName)
result = iSqlDialect.GetForeignKeyConstraint(tableName, columnName, refTableName, refColumnName)

Inline FOREIGN KEY constraint clause for use inside CREATE TABLE.

GetIdentityColumnSuffix
public string GetIdentityColumnSuffix(string pkConstraintName)
result = iSqlDialect.GetIdentityColumnSuffix(pkConstraintName)

Same as GetIdentityColumnSuffix, but names the PRIMARY KEY constraint. Without a name the database invents one — PK__Table__hash on SQL Server, table_pkey on PostgreSQL — which no naming convention can match.

pkConstraintName
Constraint name, normally from String).

返回值: The column-definition suffix carrying the named constraint.

GetIdentityColumnSuffix
public string GetIdentityColumnSuffix()
result = iSqlDialect.GetIdentityColumnSuffix()

Suffix for an identity (auto-increment primary key) column definition.

GetIdentitySelect
public string GetIdentitySelect(string idCol)
result = iSqlDialect.GetIdentitySelect(idCol)

SQL expression that returns the identity value of the last insert.

GetIntegerToDecimalCastSqlType
public string GetIntegerToDecimalCastSqlType(int precision)
result = iSqlDialect.GetIntegerToDecimalCastSqlType(precision)

SQL type a whole number is cast to when a query converts it to Decimal.

precision
Number of digits the source integer type can hold.

返回值: The SQL type name.

GetSqlTypeName
public string GetSqlTypeName(Type clrType, int maxLength)
result = iSqlDialect.GetSqlTypeName(clrType, maxLength)

Canonical SQL type name with length applied. Dialects override when the type differs by length (e.g. PostgreSQL TEXT vs VARCHAR(N)).

GetSqlTypeName
public string GetSqlTypeName(Type clrType)
result = iSqlDialect.GetSqlTypeName(clrType)

Returns the SQL type name for a CLR type.

GetStoredMaxLength
public int GetStoredMaxLength(Type clrType, int maxLength)
result = iSqlDialect.GetStoredMaxLength(clrType, maxLength)

The length the database reports for a column created with the declared length: -1 when the dialect stores it unbounded, as SQL Server does past NVARCHAR(4000) and VARBINARY(8000).

NewId
public string NewId()
result = iSqlDialect.NewId()

Generates a new unique identifier.

NormalizeDbType
public string NormalizeDbType(string dbTypeName)
result = iSqlDialect.NormalizeDbType(dbTypeName)

Normalises a raw database type name to the canonical form used by this dialect.

Now
public string Now()
result = iSqlDialect.Now()

Current local date/time.

PrepareParameter
public void PrepareParameter(DbParameter parameter)
iSqlDialect.PrepareParameter(parameter)

Final-stage massaging of a fully populated DbParameter before it leaves the ORM layer. Lets a dialect adjust provider-specific type metadata that the generic DbType hint can't express — e.g. PostgreSQL needs timestamptz binding for UTC-kind DateTime values, which only Npgsql's own NpgsqlDbType property can express. Default is a no-op.

QuoteIdentifier
public string QuoteIdentifier(string identifier)
result = iSqlDialect.QuoteIdentifier(identifier)

Quotes an identifier (table name, column name).

ReadDbCompressionsAsync
public Task<IReadOnlyList<DbTableCompressionInfo>> ReadDbCompressionsAsync(DbConnection connection, string tableSchema, CancellationToken cancellationToken)
result = iSqlDialect.ReadDbCompressionsAsync(connection, tableSchema, cancellationToken)

Reads how each table is packed on disk. Databases without the concept report every table as None, which matches an entity that declares nothing.

connection
An open database connection.
tableSchema
Schema name; dialect default when .
cancellationToken
Cancellation token.

返回值: One row per table.

ReadDbForeignKeysAsync
public Task<IReadOnlyList<DbForeignKeyInfo>> ReadDbForeignKeysAsync(DbConnection connection, string tableSchema, CancellationToken cancellationToken)
result = iSqlDialect.ReadDbForeignKeysAsync(connection, tableSchema, cancellationToken)

Reads foreign-key metadata from a live database. Used by the schema migrator to detect missing/extra FK constraints on tables that already exist.

connection
An open database connection.
tableSchema
Schema name (e.g. "dbo" or "public"); dialect default when .
cancellationToken
Cancellation token.

返回值: One row per FK column — compound FKs surface as multiple rows.

ReadDbIndexesAsync
public Task<IReadOnlyList<DbIndexInfo>> ReadDbIndexesAsync(DbConnection connection, string tableSchema, CancellationToken cancellationToken)
result = iSqlDialect.ReadDbIndexesAsync(connection, tableSchema, cancellationToken)

Reads index metadata from a live database. Used by the schema migrator to detect missing entity-declared [Index] / [Unique] attributes on tables that already exist. Composite indexes are returned as multiple rows sharing IndexName with ascending ColumnOrdinal.

connection
An open database connection.
tableSchema
Schema name (e.g. "dbo" or "public"); dialect default when .
cancellationToken
Cancellation token.

返回值: One row per indexed column — composite indexes surface as multiple rows.

ReadDbSchemaAsync
public Task<IReadOnlyList<DbColumnInfo>> ReadDbSchemaAsync(DbConnection connection, string tableSchema, CancellationToken cancellationToken)
result = iSqlDialect.ReadDbSchemaAsync(connection, tableSchema, cancellationToken)

Reads column metadata from a live database.

SysNow
public string SysNow()
result = iSqlDialect.SysNow()

System local date/time with offset.

SysUtcNow
public string SysUtcNow()
result = iSqlDialect.SysUtcNow()

System UTC date/time with offset.

UtcNow
public string UtcNow()
result = iSqlDialect.UtcNow()

Current UTC date/time.