Table of Contents

Class SqlServerGenerator

Namespace
FluentCommand.Query.Generators
Assembly
FluentCommand.dll

Provides a SQL generator for SQL Server, implementing SQL statement and expression generation with SQL Server-specific syntax and conventions.

public class SqlServerGenerator : IQueryGenerator
Inheritance
SqlServerGenerator
Implements
Derived
Inherited Members

Constructors

SqlServerGenerator()

public SqlServerGenerator()

Methods

AggregateExpression(AggregateExpression)

Builds a SQL aggregate expression (e.g., COUNT, SUM) from the specified AggregateExpression(AggregateExpression).

public virtual string AggregateExpression(AggregateExpression aggregateExpression)

Parameters

aggregateExpression AggregateExpression

The AggregateExpression(AggregateExpression) representing the aggregate function.

Returns

string

A SQL aggregate expression string.

Exceptions

ArgumentNullException

Thrown if aggregateExpression is null.

BuildDelete(DeleteStatement)

Builds a SQL DELETE statement for SQL Server, including support for OUTPUT, FROM, JOIN, WHERE, and comments.

public virtual string BuildDelete(DeleteStatement deleteStatement)

Parameters

deleteStatement DeleteStatement

The DeleteStatement containing the DELETE statement configuration.

Returns

string

A SQL DELETE statement string for SQL Server.

Exceptions

ArgumentException

Thrown if the table is not specified.

BuildInsert(InsertStatement)

Builds a SQL INSERT statement for SQL Server, including support for OUTPUT and comments.

public virtual string BuildInsert(InsertStatement insertStatement)

Parameters

insertStatement InsertStatement

The InsertStatement containing the INSERT statement configuration.

Returns

string

A SQL INSERT statement string for SQL Server.

Exceptions

ArgumentNullException

Thrown if insertStatement is null.

ArgumentException

Thrown if the table or values are not specified.

BuildOrder(IReadOnlyCollection<SortExpression>)

Builds a SQL ORDER BY clause from the specified collection of SortExpression(SortExpression) objects.

public virtual string BuildOrder(IReadOnlyCollection<SortExpression> sortExpressions)

Parameters

sortExpressions IReadOnlyCollection<SortExpression>

A collection of SortExpression(SortExpression) objects representing sort conditions.

Returns

string

A SQL ORDER BY clause string, or null if no expressions are provided.

BuildSelect(SelectStatement)

Builds a SQL SELECT statement for SQL Server, including support for JOIN, WHERE, GROUP BY, ORDER BY, LIMIT, and comments.

public virtual string BuildSelect(SelectStatement selectStatement)

Parameters

selectStatement SelectStatement

The SelectStatement containing the SELECT statement configuration.

Returns

string

A SQL SELECT statement string for SQL Server.

Exceptions

ArgumentException

Thrown if no table is specified in selectStatement.

BuildUpdate(UpdateStatement)

Builds a SQL UPDATE statement for SQL Server, including support for OUTPUT, FROM, JOIN, WHERE, and comments.

public virtual string BuildUpdate(UpdateStatement updateStatement)

Parameters

updateStatement UpdateStatement

The UpdateStatement containing the UPDATE statement configuration.

Returns

string

A SQL UPDATE statement string for SQL Server.

Exceptions

ArgumentException

Thrown if the table or update values are not specified.

BuildWhere(IReadOnlyCollection<WhereExpression>)

Builds a SQL WHERE clause from the specified collection of WhereExpression(WhereExpression) objects.

public virtual string BuildWhere(IReadOnlyCollection<WhereExpression> whereExpressions)

Parameters

whereExpressions IReadOnlyCollection<WhereExpression>

A collection of WhereExpression(WhereExpression) objects representing WHERE conditions.

Returns

string

A SQL WHERE clause string, or null if no expressions are provided.

ColumnExpression(ColumnExpression)

Builds a SQL column expression from the specified ColumnExpression.

public virtual string ColumnExpression(ColumnExpression columnExpression)

Parameters

columnExpression ColumnExpression

The ColumnExpression representing the column.

Returns

string

A SQL column expression string.

Exceptions

ArgumentNullException

Thrown if columnExpression is null.

ArgumentException

Thrown if the column name is not specified.

CommentExpression(string)

Builds a SQL comment expression.

public virtual string CommentExpression(string comment)

Parameters

comment string

The comment text.

Returns

string

A SQL comment string.

GroupExpression(GroupExpression)

Builds a SQL GROUP BY expression from the specified GroupExpression(GroupExpression).

public virtual string GroupExpression(GroupExpression groupExpression)

Parameters

groupExpression GroupExpression

The GroupExpression(GroupExpression) representing the group by condition.

Returns

string

A SQL GROUP BY expression string.

Exceptions

ArgumentNullException

Thrown if groupExpression is null.

JoinExpression(JoinExpression)

Builds a SQL JOIN expression from the specified JoinExpression(JoinExpression).

public virtual string JoinExpression(JoinExpression joinExpression)

Parameters

joinExpression JoinExpression

The JoinExpression(JoinExpression) representing the join operation.

Returns

string

A SQL JOIN expression string.

Exceptions

ArgumentNullException

Thrown if joinExpression is null.

ArgumentException

Thrown if required properties are not specified.

LimitExpression(LimitExpression)

Builds a SQL LIMIT/OFFSET expression for SQL Server.

public virtual string LimitExpression(LimitExpression limitExpression)

Parameters

limitExpression LimitExpression

The LimitExpression(LimitExpression) representing the limit and offset.

Returns

string

A SQL LIMIT/OFFSET expression string for SQL Server, or an empty string if not applicable.

LogicalExpression(IReadOnlyCollection<WhereExpression>, LogicalOperators)

Builds a logical SQL expression (e.g., AND/OR group) from the specified WHERE expressions and logical operator.

public virtual string LogicalExpression(IReadOnlyCollection<WhereExpression> whereExpressions, LogicalOperators logicalOperator)

Parameters

whereExpressions IReadOnlyCollection<WhereExpression>

A collection of WhereExpression(WhereExpression) objects representing conditions.

logicalOperator LogicalOperators

The LogicalOperators value to combine the expressions.

Returns

string

A logical SQL expression string, or an empty string if no expressions are provided.

ParseIdentifier(string)

Parses a quoted identifier and returns the unquoted name for SQL Server.

public virtual string ParseIdentifier(string name)

Parameters

name string

The quoted identifier.

Returns

string

The unquoted identifier name.

QuoteIdentifier(string)

Quotes an identifier (such as a table or column name) for SQL Server, using square brackets.

public virtual string QuoteIdentifier(string name)

Parameters

name string

The identifier to quote.

Returns

string

The quoted identifier, or the original name if quoting is not required.

SelectExpression(ColumnExpression)

Builds a SQL SELECT column or aggregate expression.

public virtual string SelectExpression(ColumnExpression columnExpression)

Parameters

columnExpression ColumnExpression

The ColumnExpression or AggregateExpression to select.

Returns

string

SortExpression(SortExpression)

Builds a SQL sort expression from the specified SortExpression(SortExpression).

public virtual string SortExpression(SortExpression sortExpression)

Parameters

sortExpression SortExpression

The SortExpression(SortExpression) representing the sort condition.

Returns

string

A SQL sort expression string.

Exceptions

ArgumentNullException

Thrown if sortExpression is null.

ArgumentException

Thrown if the column name is not specified.

TableExpression(TableExpression)

Builds a SQL table expression from the specified TableExpression(TableExpression).

public virtual string TableExpression(TableExpression tableExpression)

Parameters

tableExpression TableExpression

The TableExpression(TableExpression) representing the table.

Returns

string

A SQL table expression string.

Exceptions

ArgumentNullException

Thrown if tableExpression is null.

ArgumentException

Thrown if the table name is not specified.

UpdateExpression(UpdateExpression)

Builds a SQL update expression from the specified UpdateExpression(UpdateExpression).

public virtual string UpdateExpression(UpdateExpression updateExpression)

Parameters

updateExpression UpdateExpression

The UpdateExpression(UpdateExpression) representing the update operation.

Returns

string

A SQL update expression string.

Exceptions

ArgumentNullException

Thrown if updateExpression is null.

ArgumentException

Thrown if required properties are not specified.

WhereExpression(WhereExpression)

Builds a SQL WHERE expression from the specified WhereExpression(WhereExpression).

public virtual string WhereExpression(WhereExpression whereExpression)

Parameters

whereExpression WhereExpression

The WhereExpression(WhereExpression) representing the condition.

Returns

string

A SQL WHERE expression string.

Exceptions

ArgumentNullException

Thrown if whereExpression is null.

ArgumentException

Thrown if required properties are not specified.