SqlServerDialect
SQL Server dialect implementation.
Inherits: SqlDialectBase
Properties
public override string BatchSeparator { get; }
value = sqlServerDialect.BatchSeparator
Batch separator (e.g. GO for SQL Server). Empty when no separation is needed.
public override bool CanAlterColumnWithDependents { get; }
value = sqlServerDialect.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 override string EmptyBinaryLiteral { get; }
value = sqlServerDialect.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 override int MaxParameters { get; }
value = sqlServerDialect.MaxParameters
Maximum number of parameters allowed in a single statement. SQL Server: 2100, SQLite: 999, PostgreSQL: 65535, MySQL: 65535.
public override string ParameterPrefix { get; }
value = sqlServerDialect.ParameterPrefix
Parameter prefix (e.g. @ for SQL Server, $ for PostgreSQL).
Methods
public override void AppendAlterColumn(StringBuilder sb, string tableName, string columnName, Type clrType, bool isNullable, int maxLength, int precision, int scale, DbColumnInfo live)
sqlServerDialect.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 override void AppendAlterNullability(StringBuilder sb, string tableName, string columnName, bool isNullable, DbColumnInfo live)
sqlServerDialect.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 override void AppendCreateTable(StringBuilder sb, string tableName, string columnDefs)
sqlServerDialect.AppendCreateTable(sb, tableName, columnDefs)
Appends CREATE TABLE [IF NOT EXISTS] statement.
public override void AppendDeleteBy(StringBuilder sb, string tableName, string[] whereColumns)
sqlServerDialect.AppendDeleteBy(sb, tableName, whereColumns)
Appends a DELETE … WHERE statement.
public override void AppendDropIndex(StringBuilder sb, string tableName, string indexName)
sqlServerDialect.AppendDropIndex(sb, tableName, indexName)
Appends DROP INDEX.
public override void AppendDropTable(StringBuilder sb, string tableName)
sqlServerDialect.AppendDropTable(sb, tableName)
Appends DROP TABLE [IF EXISTS] statement.
public override void AppendFallbackOrderBy(StringBuilder sb)
sqlServerDialect.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 override void AppendPagination(StringBuilder sb, long? skip, long? take, bool hasOrderBy)
sqlServerDialect.AppendPagination(sb, skip, take, hasOrderBy)
Appends literal pagination (LIMIT/OFFSET or OFFSET/FETCH) with values.
public override void AppendPaginationParams(StringBuilder sb, string skipParamExpr, string takeParamExpr)
sqlServerDialect.AppendPaginationParams(sb, skipParamExpr, takeParamExpr)
Appends parameterised pagination with already-prefixed parameter expressions (e.g. @skip, @take).
public override void AppendSetCompression(StringBuilder builder, string tableName, DataCompressions compression)
sqlServerDialect.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 override void AppendUpdateBy(StringBuilder sb, string tableName, string[] setColumns, string[] whereColumns)
sqlServerDialect.AppendUpdateBy(sb, tableName, setColumns, whereColumns)
Appends an UPDATE … SET … WHERE statement.
public override void AppendUpsert(StringBuilder sb, string tableName, string[] allColumns, string[] keyColumns)
sqlServerDialect.AppendUpsert(sb, tableName, allColumns, keyColumns)
Appends a UPSERT statement (MERGE on SQL Server, INSERT … ON CONFLICT on PostgreSQL/SQLite).
public override string FormatSkip(string skip)
result = sqlServerDialect.FormatSkip(skip)
Renders a SKIP/OFFSET clause from a parameter expression.
public override string FormatTake(string take)
result = sqlServerDialect.FormatTake(take)
Renders a TAKE/FETCH clause from a parameter expression.
public override string GetColumnTypeName(Type clrType, int maxLength, int precision, int scale)
result = sqlServerDialect.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 override string GetIdentityColumnSuffix()
result = sqlServerDialect.GetIdentityColumnSuffix()
Suffix for an identity (auto-increment primary key) column definition.
public override string GetIdentitySelect(string idCol)
result = sqlServerDialect.GetIdentitySelect(idCol)
SQL expression that returns the identity value of the last insert.
public override string GetSqlTypeName(Type clrType)
result = sqlServerDialect.GetSqlTypeName(clrType)
Returns the SQL type name for a CLR type.
public override int GetStoredMaxLength(Type clrType, int maxLength)
result = sqlServerDialect.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 override string NewId()
result = sqlServerDialect.NewId()
Generates a new unique identifier.
public override string NormalizeDbType(string dbTypeName)
result = sqlServerDialect.NormalizeDbType(dbTypeName)
Normalises a raw database type name to the canonical form used by this dialect.
public override string QuoteIdentifier(string identifier)
result = sqlServerDialect.QuoteIdentifier(identifier)
Quotes an identifier (table name, column name).
public override Task<IReadOnlyList<DbTableCompressionInfo>> ReadDbCompressionsAsync(DbConnection connection, string tableSchema, CancellationToken cancellationToken)
result = sqlServerDialect.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.
Returns: One row per table.
public override Task<IReadOnlyList<DbForeignKeyInfo>> ReadDbForeignKeysAsync(DbConnection connection, string tableSchema, CancellationToken cancellationToken)
result = sqlServerDialect.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.
Returns: One row per FK column — compound FKs surface as multiple rows.
public override Task<IReadOnlyList<DbIndexInfo>> ReadDbIndexesAsync(DbConnection connection, string tableSchema, CancellationToken cancellationToken)
result = sqlServerDialect.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.
Returns: One row per indexed column — composite indexes surface as multiple rows.
public override Task<IReadOnlyList<DbColumnInfo>> ReadDbSchemaAsync(DbConnection connection, string tableSchema, CancellationToken cancellationToken)
result = sqlServerDialect.ReadDbSchemaAsync(connection, tableSchema, cancellationToken)
Reads column metadata from a live database.
public static void Register(DbProviderFactory factory)
SqlServerDialect.Register(factory)
Registers the SQL Server dialect and provider factory with DatabaseProviderRegistry.
- factory
- The DbProviderFactory for SQL Server.
public override string SysNow()
result = sqlServerDialect.SysNow()
System local date/time with offset.
public override string SysUtcNow()
result = sqlServerDialect.SysUtcNow()
System UTC date/time with offset.
Fields
public static readonly SqlServerDialect Instance
value = SqlServerDialect.Instance
Singleton instance.