Table of Contents

Class WhereBuilder<TBuilder>

Namespace
FluentCommand.Query
Assembly
FluentCommand.dll

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

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

Type Parameters

TBuilder

The type of the builder for fluent chaining.

Inheritance
WhereBuilder<TBuilder>
Implements
Derived
Inherited Members

Constructors

WhereBuilder(IQueryGenerator, List<QueryParameter>, LogicalOperators)

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

protected WhereBuilder(IQueryGenerator queryGenerator, List<QueryParameter> parameters, LogicalOperators logicalOperator = LogicalOperators.And)

Parameters

queryGenerator IQueryGenerator

The IQueryGenerator used to generate SQL expressions.

parameters List<QueryParameter>

The list of QueryParameter objects for the query.

logicalOperator LogicalOperators

The logical operator (LogicalOperators) to combine WHERE expressions. Defaults to And.

Properties

LogicalOperator

Gets the logical operator used to combine WHERE expressions.

protected LogicalOperators LogicalOperator { get; }

Property Value

LogicalOperators

The LogicalOperators value.

WhereExpressions

Gets the collection of WHERE expressions for the query.

protected HashSet<WhereExpression> WhereExpressions { get; }

Property Value

HashSet<WhereExpression>

A HashSet<T> containing the WHERE expressions.

Methods

WhereAnd(Action<LogicalBuilder>)

Adds a logical AND group of WHERE clauses using the specified builder action.

public TBuilder WhereAnd(Action<LogicalBuilder> builder)

Parameters

builder Action<LogicalBuilder>

An action that configures the logical AND group using a LogicalBuilder.

Returns

TBuilder

The same builder instance for method chaining.

WhereIf<TValue>(string, TValue, FilterOperators, Func<string, TValue, bool>)

Conditionally adds a WHERE clause for the specified column, value, and operator if the condition is met.

public TBuilder WhereIf<TValue>(string columnName, TValue parameterValue, FilterOperators filterOperator = FilterOperators.Equal, Func<string, TValue, bool> condition = null)

Parameters

columnName string

The name of the column.

parameterValue TValue

The value to compare.

filterOperator FilterOperators

The filter operator (FilterOperators). Defaults to Equal.

condition Func<string, TValue, bool>

A function that determines whether to add the clause. If null, the clause is always added.

Returns

TBuilder

The same builder instance for method chaining.

Type Parameters

TValue

The type of the value.

WhereIf<TValue>(string, TValue, string, FilterOperators, Func<string, TValue, bool>)

Conditionally adds a WHERE clause for the specified column, value, operator, and table alias if the condition is met.

public TBuilder WhereIf<TValue>(string columnName, TValue parameterValue, string tableAlias, FilterOperators filterOperator = FilterOperators.Equal, Func<string, TValue, bool> condition = null)

Parameters

columnName string

The name of the column.

parameterValue TValue

The value to compare.

tableAlias string

The table alias, or null if not applicable.

filterOperator FilterOperators

The filter operator (FilterOperators). Defaults to Equal.

condition Func<string, TValue, bool>

A function that determines whether to add the clause. If null, the clause is always added.

Returns

TBuilder

The same builder instance for method chaining.

Type Parameters

TValue

The type of the value.

WhereInIf<TValue>(string, IEnumerable<TValue>, Func<string, IEnumerable<TValue>, bool>)

Conditionally adds a WHERE IN clause for the specified column and values if the condition is met.

public TBuilder WhereInIf<TValue>(string columnName, IEnumerable<TValue> parameterValues, Func<string, IEnumerable<TValue>, bool> condition = null)

Parameters

columnName string

The name of the column.

parameterValues IEnumerable<TValue>

The collection of values for the IN clause.

condition Func<string, IEnumerable<TValue>, bool>

A function that determines whether to add the clause. If null, the clause is always added.

Returns

TBuilder

The same builder instance for method chaining.

Type Parameters

TValue

The type of the values.

WhereInIf<TValue>(string, IEnumerable<TValue>, string, Func<string, IEnumerable<TValue>, bool>)

Conditionally adds a WHERE IN clause for the specified column, values, and table alias if the condition is met.

public TBuilder WhereInIf<TValue>(string columnName, IEnumerable<TValue> parameterValues, string tableAlias, Func<string, IEnumerable<TValue>, bool> condition = null)

Parameters

columnName string

The name of the column.

parameterValues IEnumerable<TValue>

The collection of values for the IN clause.

tableAlias string

The table alias, or null if not applicable.

condition Func<string, IEnumerable<TValue>, bool>

A function that determines whether to add the clause. If null, the clause is always added.

Returns

TBuilder

The same builder instance for method chaining.

Type Parameters

TValue

The type of the values.

WhereIn<TValue>(string, IEnumerable<TValue>, string)

Adds a WHERE IN clause for the specified column, values, and optional table alias.

public TBuilder WhereIn<TValue>(string columnName, IEnumerable<TValue> parameterValues, string tableAlias = null)

Parameters

columnName string

The name of the column.

parameterValues IEnumerable<TValue>

The collection of values for the IN clause.

tableAlias string

The table alias, or null if not applicable.

Returns

TBuilder

The same builder instance for method chaining.

Type Parameters

TValue

The type of the values.

WhereOr(Action<LogicalBuilder>)

Adds a logical OR group of WHERE clauses using the specified builder action.

public TBuilder WhereOr(Action<LogicalBuilder> builder)

Parameters

builder Action<LogicalBuilder>

An action that configures the logical OR group using a LogicalBuilder.

Returns

TBuilder

The same builder instance for method chaining.

WhereRaw(string, IEnumerable<QueryParameter>)

Adds a raw WHERE clause to the query.

public TBuilder WhereRaw(string whereClause, IEnumerable<QueryParameter> parameters = null)

Parameters

whereClause string

The raw SQL WHERE clause.

parameters IEnumerable<QueryParameter>

The collection of QueryParameter objects for the clause, or null if none.

Returns

TBuilder

The same builder instance for method chaining.

Exceptions

ArgumentException

Thrown if whereClause is null or empty.

WhereRawIf(string, IEnumerable<QueryParameter>, Func<string, IEnumerable<QueryParameter>, bool>)

Conditionally adds a raw WHERE clause to the query if the condition is met.

public TBuilder WhereRawIf(string whereClause, IEnumerable<QueryParameter> parameters = null, Func<string, IEnumerable<QueryParameter>, bool> condition = null)

Parameters

whereClause string

The raw SQL WHERE clause.

parameters IEnumerable<QueryParameter>

The collection of QueryParameter objects for the clause, or null if none.

condition Func<string, IEnumerable<QueryParameter>, bool>

A function that determines whether to add the clause. If null, the clause is always added.

Returns

TBuilder

The same builder instance for method chaining.

Where<TValue>(string, TValue, FilterOperators)

Adds a WHERE clause for the specified column, value, and operator.

public TBuilder Where<TValue>(string columnName, TValue parameterValue, FilterOperators filterOperator = FilterOperators.Equal)

Parameters

columnName string

The name of the column.

parameterValue TValue

The value to compare.

filterOperator FilterOperators

The filter operator (FilterOperators). Defaults to Equal.

Returns

TBuilder

The same builder instance for method chaining.

Type Parameters

TValue

The type of the value.

Where<TValue>(string, TValue, string, FilterOperators)

Adds a WHERE clause for the specified column, value, operator, and table alias.

public TBuilder Where<TValue>(string columnName, TValue parameterValue, string tableAlias, FilterOperators filterOperator = FilterOperators.Equal)

Parameters

columnName string

The name of the column.

parameterValue TValue

The value to compare.

tableAlias string

The table alias, or null if not applicable.

filterOperator FilterOperators

The filter operator (FilterOperators). Defaults to Equal.

Returns

TBuilder

The same builder instance for method chaining.

Type Parameters

TValue

The type of the value.