Table of Contents

Class OrderBuilder<TBuilder>

Namespace
FluentCommand.Query
Assembly
FluentCommand.dll

Provides a generic base class for building SQL ORDER BY clauses with fluent, chainable methods.

public abstract class OrderBuilder<TBuilder> : StatementBuilder<TBuilder>, IStatementBuilder, IQueryBuilder where TBuilder : OrderBuilder<TBuilder>

Type Parameters

TBuilder

The type of the builder for fluent chaining.

Inheritance
OrderBuilder<TBuilder>
Implements
Derived
Inherited Members

Constructors

OrderBuilder(IQueryGenerator, List<QueryParameter>)

Initializes a new instance of the OrderBuilder<TBuilder> class.

protected OrderBuilder(IQueryGenerator queryGenerator, List<QueryParameter> parameters)

Parameters

queryGenerator IQueryGenerator

The IQueryGenerator used to generate SQL expressions.

parameters List<QueryParameter>

The list of QueryParameter objects for the query.

Properties

SortExpressions

Gets the collection of sort expressions for the ORDER BY clause.

protected HashSet<SortExpression> SortExpressions { get; }

Property Value

HashSet<SortExpression>

A HashSet<T> containing the sort expressions.

Methods

BuildStatement()

Builds the SQL ORDER BY statement using the current sort expressions.

public override QueryStatement BuildStatement()

Returns

QueryStatement

A QueryStatement containing the SQL ORDER BY clause and its parameters, or null if no sort expressions are present.

OrderBy(string, SortDirections)

Adds an ORDER BY clause with the specified column name and sort direction.

public TBuilder OrderBy(string columnName, SortDirections sortDirection = SortDirections.Ascending)

Parameters

columnName string

The name of the column to sort by.

sortDirection SortDirections

The sort direction (default is Ascending).

Returns

TBuilder

The same builder instance for method chaining.

OrderBy(string, string, SortDirections)

Adds an ORDER BY clause with the specified column name, sort direction, and table alias.

public TBuilder OrderBy(string columnName, string tableAlias, SortDirections sortDirection = SortDirections.Ascending)

Parameters

columnName string

The name of the column to sort by.

tableAlias string

The alias of the table (optional).

sortDirection SortDirections

The sort direction (default is Ascending).

Returns

TBuilder

The same builder instance for method chaining.

OrderByIf(string, string, SortDirections, Func<string, bool>)

Conditionally adds an ORDER BY clause with the specified column name, sort direction, and table alias.

public TBuilder OrderByIf(string columnName, string tableAlias = null, SortDirections sortDirection = SortDirections.Ascending, Func<string, bool> condition = null)

Parameters

columnName string

The name of the column to sort by.

tableAlias string

The alias of the table (optional).

sortDirection SortDirections

The sort direction (default is Ascending).

condition Func<string, bool>

A function that determines whether to add the ORDER BY clause, based on the column name. If null, the clause is always added.

Returns

TBuilder

The same builder instance for method chaining.

OrderByRaw(IEnumerable<string>)

Adds multiple raw ORDER BY clauses to the query.

public TBuilder OrderByRaw(IEnumerable<string> sortExpressions)

Parameters

sortExpressions IEnumerable<string>

A collection of raw SQL ORDER BY clauses.

Returns

TBuilder

The same builder instance for method chaining.

Exceptions

ArgumentNullException

Thrown if sortExpressions is null.

OrderByRaw(string)

Adds a raw ORDER BY clause to the query.

public TBuilder OrderByRaw(string sortExpression)

Parameters

sortExpression string

The raw SQL ORDER BY clause.

Returns

TBuilder

The same builder instance for method chaining.

OrderByRawIf(string, Func<string, bool>)

Conditionally adds a raw ORDER BY clause to the query.

public TBuilder OrderByRawIf(string sortExpression, Func<string, bool> condition = null)

Parameters

sortExpression string

The raw SQL ORDER BY clause.

condition Func<string, bool>

A function that determines whether to add the ORDER BY clause, based on the expression. If null, the clause is always added.

Returns

TBuilder

The same builder instance for method chaining.