ISqlDialect
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.
プロパティ
public string BatchSeparator { get; }
value = iSqlDialect.BatchSeparator
Batch separator (e.g. GO for SQL Server). Empty when no separation is needed.
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).
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.
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.
public string ConcatOperator { get; }
value = iSqlDialect.ConcatOperator
SQL string concatenation operator.
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.
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).
public string FalseLiteral { get; }
value = iSqlDialect.FalseLiteral
SQL literal for boolean false.
public string IsNullFunction { get; }
value = iSqlDialect.IsNullFunction
Function name for null-coalescing.
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.
public string LenFunction { get; }
value = iSqlDialect.LenFunction
Function name for string length.
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.
public string ParameterPrefix { get; }
value = iSqlDialect.ParameterPrefix
Parameter prefix (e.g. @ for SQL Server, $ for PostgreSQL).
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.
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.
public string TrueLiteral { get; }
value = iSqlDialect.TrueLiteral
SQL literal for boolean true.
public string UnicodePrefix { get; }
value = iSqlDialect.UnicodePrefix
Unicode string-literal prefix (e.g. N for SQL Server).
メソッド
public void AppendAddColumn(StringBuilder sb, string tableName, string columnName, string columnDef)
iSqlDialect.AppendAddColumn(sb, tableName, columnName, columnDef)
Appends ALTER TABLE ADD COLUMN.
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.
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.
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.
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.
public void AppendCreateTable(StringBuilder sb, string tableName, string columnDefs)
iSqlDialect.AppendCreateTable(sb, tableName, columnDefs)
Appends CREATE TABLE [IF NOT EXISTS] statement.
public void AppendDateAdd(StringBuilder sb, string part, string amountSql, string sourceSql)
iSqlDialect.AppendDateAdd(sb, part, amountSql, sourceSql)
Appends a DATEADD-style expression.
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.
public void AppendDatePartClose(StringBuilder sb)
iSqlDialect.AppendDatePartClose(sb)
Closes a date-part extraction expression opened by String).
public void AppendDatePartOpen(StringBuilder sb, string part)
iSqlDialect.AppendDatePartOpen(sb, part)
Opens a date-part extraction expression (closed by StringBuilder)).
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.
public void AppendDeleteBy(StringBuilder sb, string tableName, string[] whereColumns)
iSqlDialect.AppendDeleteBy(sb, tableName, whereColumns)
Appends a DELETE … WHERE statement.
public void AppendDropColumn(StringBuilder sb, string tableName, string columnName)
iSqlDialect.AppendDropColumn(sb, tableName, columnName)
Appends ALTER TABLE DROP COLUMN.
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.
public void AppendDropIndex(StringBuilder sb, string tableName, string indexName)
iSqlDialect.AppendDropIndex(sb, tableName, indexName)
Appends DROP INDEX.
public void AppendDropTable(StringBuilder sb, string tableName)
iSqlDialect.AppendDropTable(sb, tableName)
Appends DROP TABLE [IF EXISTS] statement.
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.
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.
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.
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.
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.
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).
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.
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.
public void AppendTrimClose(StringBuilder sb)
iSqlDialect.AppendTrimClose(sb)
Closes a TRIM expression opened by StringBuilder).
public void AppendTrimOpen(StringBuilder sb)
iSqlDialect.AppendTrimOpen(sb)
Opens a TRIM expression (closed by StringBuilder)).
public void AppendUpdateBy(StringBuilder sb, string tableName, string[] setColumns, string[] whereColumns)
iSqlDialect.AppendUpdateBy(sb, tableName, setColumns, whereColumns)
Appends an UPDATE … SET … WHERE statement.
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.
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).
public object ConvertFromDbValue(object value, Type targetType)
result = iSqlDialect.ConvertFromDbValue(value, targetType)
Converts a database value to the requested CLR target type.
public object ConvertToDbValue(object value, Type clrType)
result = iSqlDialect.ConvertToDbValue(value, clrType)
Converts a CLR value to the form a database driver expects.
public string FormatSkip(string skip)
result = iSqlDialect.FormatSkip(skip)
Renders a SKIP/OFFSET clause from a parameter expression.
public string FormatTake(string take)
result = iSqlDialect.FormatTake(take)
Renders a TAKE/FETCH clause from a parameter expression.
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.
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.
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.
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.
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.
public string GetIdentityColumnSuffix()
result = iSqlDialect.GetIdentityColumnSuffix()
Suffix for an identity (auto-increment primary key) column definition.
public string GetIdentitySelect(string idCol)
result = iSqlDialect.GetIdentitySelect(idCol)
SQL expression that returns the identity value of the last insert.
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.
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)).
public string GetSqlTypeName(Type clrType)
result = iSqlDialect.GetSqlTypeName(clrType)
Returns the SQL type name for a CLR type.
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).
public string NormalizeDbType(string dbTypeName)
result = iSqlDialect.NormalizeDbType(dbTypeName)
Normalises a raw database type name to the canonical form used by this dialect.
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.
public string QuoteIdentifier(string identifier)
result = iSqlDialect.QuoteIdentifier(identifier)
Quotes an identifier (table name, column name).
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.
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.
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.
public Task<IReadOnlyList<DbColumnInfo>> ReadDbSchemaAsync(DbConnection connection, string tableSchema, CancellationToken cancellationToken)
result = iSqlDialect.ReadDbSchemaAsync(connection, tableSchema, cancellationToken)
Reads column metadata from a live database.
public string SysUtcNow()
result = iSqlDialect.SysUtcNow()
System UTC date/time with offset.