Table of Contents

Class WhereEntityBuilder<TEntity>

Namespace
FluentCommand.Query
Assembly
FluentCommand.dll

Provides a builder for constructing SQL WHERE clauses for a specific entity type.

public class WhereEntityBuilder<TEntity> : WhereBuilder<WhereEntityBuilder<TEntity>>, IStatementBuilder, IQueryBuilder, IWhereEntityBuilder<TEntity, WhereEntityBuilder<TEntity>> where TEntity : class

Type Parameters

TEntity

The type of the entity.

Inheritance
WhereEntityBuilder<TEntity>
Implements
Inherited Members

Constructors

WhereEntityBuilder(IQueryGenerator, List<QueryParameter>, LogicalOperators)

Initializes a new instance of the WhereEntityBuilder<TEntity> class.

public WhereEntityBuilder(IQueryGenerator queryGenerator, List<QueryParameter> parameters, LogicalOperators logicalOperator = LogicalOperators.And)

Parameters

queryGenerator IQueryGenerator

The query generator used to build SQL statements.

parameters List<QueryParameter>

The collection of query parameters.

logicalOperator LogicalOperators

The logical operator to combine WHERE expressions (default is And).

Methods

BuildStatement()

Builds the SQL WHERE statement using the current expressions and parameters.

public override QueryStatement BuildStatement()

Returns

QueryStatement

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

WhereAnd(Action<LogicalEntityBuilder<TEntity>>)

Adds a logical AND group to the WHERE clause using the specified builder action.

public WhereEntityBuilder<TEntity> WhereAnd(Action<LogicalEntityBuilder<TEntity>> builder)

Parameters

builder Action<LogicalEntityBuilder<TEntity>>

An action that configures the logical AND group using a LogicalEntityBuilder<TEntity>.

Returns

WhereEntityBuilder<TEntity>

The builder instance for chaining further calls.

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

Conditionally adds a WHERE clause for the specified property, value, and filter operator.

public WhereEntityBuilder<TEntity> WhereIf<TValue>(Expression<Func<TEntity, TValue>> property, TValue parameterValue, FilterOperators filterOperator = FilterOperators.Equal, Func<string, TValue, bool> condition = null)

Parameters

property Expression<Func<TEntity, TValue>>

An expression selecting the property to filter on.

parameterValue TValue

The value to compare the property against.

filterOperator FilterOperators

The filter operator to use (default is Equal).

condition Func<string, TValue, bool>

A function that determines whether to add the clause, based on the property name and value. If null, the clause is always added.

Returns

WhereEntityBuilder<TEntity>

The builder instance for chaining further calls.

Type Parameters

TValue

The type of the value to compare.

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

Conditionally adds a WHERE clause for the specified property, value, filter operator, and table alias.

public WhereEntityBuilder<TEntity> WhereIf<TValue>(Expression<Func<TEntity, TValue>> property, TValue parameterValue, string tableAlias, FilterOperators filterOperator = FilterOperators.Equal, Func<string, TValue, bool> condition = null)

Parameters

property Expression<Func<TEntity, TValue>>

An expression selecting the property to filter on.

parameterValue TValue

The value to compare the property against.

tableAlias string

The table alias to use in the query.

filterOperator FilterOperators

The filter operator to use (default is Equal).

condition Func<string, TValue, bool>

A function that determines whether to add the clause, based on the table alias and value. If null, the clause is always added.

Returns

WhereEntityBuilder<TEntity>

The builder instance for chaining further calls.

Type Parameters

TValue

The type of the value to compare.

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

Conditionally adds a WHERE IN clause for the specified property and collection of values.

public WhereEntityBuilder<TEntity> WhereInIf<TValue>(Expression<Func<TEntity, TValue>> property, IEnumerable<TValue> parameterValues, Func<string, IEnumerable<TValue>, bool> condition = null)

Parameters

property Expression<Func<TEntity, TValue>>

An expression selecting the property to filter on.

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, based on the property name and values. If null, the clause is always added.

Returns

WhereEntityBuilder<TEntity>

The builder instance for chaining further calls.

Type Parameters

TValue

The type of the values to compare.

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

Conditionally adds a WHERE IN clause for the specified property, collection of values, and table alias.

public WhereEntityBuilder<TEntity> WhereInIf<TValue>(Expression<Func<TEntity, TValue>> property, IEnumerable<TValue> parameterValues, string tableAlias, Func<string, IEnumerable<TValue>, bool> condition = null)

Parameters

property Expression<Func<TEntity, TValue>>

An expression selecting the property to filter on.

parameterValues IEnumerable<TValue>

The collection of values for the IN clause.

tableAlias string

The table alias to use in the query.

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

A function that determines whether to add the clause, based on the table alias and values. If null, the clause is always added.

Returns

WhereEntityBuilder<TEntity>

The builder instance for chaining further calls.

Type Parameters

TValue

The type of the values to compare.

WhereIn<TValue>(Expression<Func<TEntity, TValue>>, IEnumerable<TValue>, string)

Adds a WHERE IN clause for the specified property and collection of values, with an optional table alias.

public WhereEntityBuilder<TEntity> WhereIn<TValue>(Expression<Func<TEntity, TValue>> property, IEnumerable<TValue> parameterValues, string tableAlias = null)

Parameters

property Expression<Func<TEntity, TValue>>

An expression selecting the property to filter on.

parameterValues IEnumerable<TValue>

The collection of values for the IN clause.

tableAlias string

The table alias to use in the query (optional).

Returns

WhereEntityBuilder<TEntity>

The builder instance for chaining further calls.

Type Parameters

TValue

The type of the values to compare.

WhereOr(Action<LogicalEntityBuilder<TEntity>>)

Adds a logical OR group to the WHERE clause using the specified builder action.

public WhereEntityBuilder<TEntity> WhereOr(Action<LogicalEntityBuilder<TEntity>> builder)

Parameters

builder Action<LogicalEntityBuilder<TEntity>>

An action that configures the logical OR group using a LogicalEntityBuilder<TEntity>.

Returns

WhereEntityBuilder<TEntity>

The builder instance for chaining further calls.

Where<TValue>(Expression<Func<TEntity, TValue>>, TValue, FilterOperators)

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

public WhereEntityBuilder<TEntity> Where<TValue>(Expression<Func<TEntity, TValue>> property, TValue parameterValue, FilterOperators filterOperator = FilterOperators.Equal)

Parameters

property Expression<Func<TEntity, TValue>>

An expression selecting the property to filter on.

parameterValue TValue

The value to compare the property against.

filterOperator FilterOperators

The filter operator to use (default is Equal).

Returns

WhereEntityBuilder<TEntity>

The builder instance for chaining further calls.

Type Parameters

TValue

The type of the value to compare.

Where<TValue>(Expression<Func<TEntity, TValue>>, TValue, string, FilterOperators)

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

public WhereEntityBuilder<TEntity> Where<TValue>(Expression<Func<TEntity, TValue>> property, TValue parameterValue, string tableAlias, FilterOperators filterOperator = FilterOperators.Equal)

Parameters

property Expression<Func<TEntity, TValue>>

An expression selecting the property to filter on.

parameterValue TValue

The value to compare the property against.

tableAlias string

The table alias to use in the query.

filterOperator FilterOperators

The filter operator to use (default is Equal).

Returns

WhereEntityBuilder<TEntity>

The builder instance for chaining further calls.

Type Parameters

TValue

The type of the value to compare.