Table of Contents

Class SqlServerDialect

Namespace
eQuantic.Core.Data.SqlServer
Assembly
eQuantic.Core.Data.SqlServer.dll

SQL Server's SQL flavour: snake_case naming, [bracketed] identifiers, OFFSET/FETCH paging (which demands an ORDER BY — the engine adds a deterministic key order when the query has none), IDENTITY keys read back with OUTPUT INSERTED, and (1=0) for the empty-IN literal. Collection columns and row-wise tuple comparisons do not exist; those clauses degrade to the gated client-side residual.

public class SqlServerDialect : SqlDialect
Inheritance
SqlServerDialect
Inherited Members

Constructors

SqlServerDialect()

Initializes the dialect (T-SQL date parts instead of EXTRACT).

public SqlServerDialect()

Properties

FalseLiteral

The literal for an always-false predicate (an empty IN); some dialects have no FALSE.

public override string FalseLiteral { get; }

Property Value

string

GeneratedKeyDdl

The DDL column suffix declaring a database-generated key (e.g. GENERATED BY DEFAULT AS IDENTITY).

public override string GeneratedKeyDdl { get; }

Property Value

string

IntrospectColumnsSql

A query listing every column of the schema in use, as four values in order: the table's name, the column's name, its type spelled the way this dialect spells it in DDL, and whether it accepts null. null when the dialect cannot read its own catalogue, which makes drift unanswerable rather than answered wrongly.

Each dialect writes its own, and composes the type in SQL rather than leaving it to be reassembled from parts afterwards. Catalogues disagree about where a type's facets live — one keeps the whole spelling in a column, another splits length from precision from fractional seconds — and the disagreement is far better settled by the store that knows the answer.

public override string? IntrospectColumnsSql { get; }

Property Value

string

Remarks

sys.columns rather than information_schema, and the type composed here rather than afterwards: only this query knows that max_length counts bytes, so an nvarchar(450) reports 900, and that -1 is how max is stored.

RequiresOrderByForLimit

Whether a limited query must carry an ORDER BY (SQL Server's OFFSET/FETCH); the key is used when unsorted.

public override bool RequiresOrderByForLimit { get; }

Property Value

bool

SupportsBulkInsert

Whether the engine has a native bulk-load path for this dialect (PostgreSQL COPY, SQL Server SqlBulkCopy, MySQL's bulk loader). BulkInsertAsync refuses on dialects that answer false rather than quietly running an ordinary batch — asking for a bulk load and getting row-by-row inserts is exactly the kind of silent cost this engine does not ship.

public override bool SupportsBulkInsert { get; }

Property Value

bool

System

The OpenTelemetry db.system value (e.g. postgresql, mysql, mssql).

public override string System { get; }

Property Value

string

Methods

AlterColumnType(string, string, string)

The DDL altering a column's type (a dialect may need a cast clause).

public override string AlterColumnType(string quotedTable, string quotedColumn, string sqlType)

Parameters

quotedTable string
quotedColumn string
sqlType string

Returns

string

BindValue(object?)

Converts a value before binding (a dialect may need CLR-side coercion, e.g. arrays); identity by default.

public override object? BindValue(object? value)

Parameters

value object

Returns

object

BulkInsertAsync(DbConnection, DbTransaction?, string, IReadOnlyList<RelationalColumn>, IReadOnlyList<object?[]>, CancellationToken)

Bulk-loads rows through the store's native mechanism. Implemented by the dialects that declare SupportsBulkInsert; each row carries the column values in columns order, already converted to their stored form by the engine.

public override Task<long> BulkInsertAsync(DbConnection connection, DbTransaction? transaction, string quotedTable, IReadOnlyList<RelationalColumn> columns, IReadOnlyList<object?[]> rows, CancellationToken cancellationToken)

Parameters

connection DbConnection

The open connection (inside the caller's transaction, when there is one).

transaction DbTransaction

The ambient transaction, or null.

quotedTable string

The quoted target table.

columns IReadOnlyList<RelationalColumn>

The target columns, in the order each row's values arrive.

rows IReadOnlyList<object[]>

The rows to load.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<long>

The number of rows loaded.

Remarks

SqlBulkCopy — the bulk-load API of the SQL Server client, streaming rows to the server without a statement per row. Column mappings are explicit (ordinal to name), so the row order the engine produces is authoritative regardless of the table's physical column order.

CreateIndexSql(string, string, string, bool, IndexMethod, string?)

The DDL creating an index with a structure and an optional filtered predicate (already rendered as a SQL fragment with inlined literals). The base dialect builds default-structure indexes, filtered or not; a method it has no structure for is rejected with guidance.

public override string CreateIndexSql(string quotedName, string quotedTable, string columns, bool unique, IndexMethod method, string? filter)

Parameters

quotedName string

The quoted index name.

quotedTable string

The quoted table.

columns string

The rendered key column list.

unique bool

Whether the index enforces uniqueness.

method IndexMethod

The index structure.

filter string

The rendered partial-index predicate, or null.

Returns

string

CreateTableSql(string, string)

Builds an idempotent CREATE TABLE statement.

public override string CreateTableSql(string quotedTable, string columnsDdl)

Parameters

quotedTable string

The quoted table.

columnsDdl string

The column declaration list.

Returns

string

InsertSql(string, string, string, string?)

Builds an INSERT, reading the generated key back when returningKey is supplied (RETURNING / OUTPUT INSERTED). The base dialect cannot read keys back — declare a client-generated key, or use a dialect that can.

public override string InsertSql(string quotedTable, string columns, string values, string? returningKey)

Parameters

quotedTable string

The quoted table.

columns string

The quoted column list.

values string

The bound value list.

returningKey string

The quoted generated-key column to read back, or null.

Returns

string

LimitClause(string, string?)

The SQL fragment limiting a query to the bound row count after the bound offset (appended after ORDER BY).

public override string LimitClause(string limitParameter, string? offsetParameter)

Parameters

limitParameter string
offsetParameter string

Returns

string

Literal(object?)

Renders a value as an inline SQL literal — DDL (a filtered index's predicate) cannot carry bind parameters. Values a dialect cannot inline are rejected with guidance.

public override string Literal(object? value)

Parameters

value object

The value (already normalized by BindValue(object?)).

Returns

string

Remarks

SQL Server booleans are bit: literals inline as 1/0.

Quote(string)

Quotes an identifier (table or column name).

public override string Quote(string identifier)

Parameters

identifier string

Returns

string

RenameTableSql(string, string)

The DDL renaming a table. The target arrives unquoted because not every dialect renames with a statement — SQL Server calls a procedure, and its second argument is a bare name.

public override string RenameTableSql(string quotedTable, string target)

Parameters

quotedTable string

The quoted table, as it is now.

target string

The name it takes, unquoted.

Returns

string

Remarks

SQL Server has no RENAME statement; it calls sp_rename, whose second argument is the new name alone — schema-qualifying or bracketing it renames the table to something containing brackets.

SizedTextType(int)

The sized text type — nvarchar(n) on SQL Server.

protected override string SizedTextType(int length)

Parameters

length int

The maximum length.

Returns

string

SqlType(Type)

The DDL type for a CLR type (used by CREATE TABLE migrations).

public override string SqlType(Type type)

Parameters

type Type

Returns

string