Table of Contents

Class SelectEntityBuilder<TEntity>

Namespace
FluentCommand.Query
Assembly
FluentCommand.dll

Provides a builder for constructing SQL SELECT statements for a specific entity type with fluent, chainable methods.

public class SelectEntityBuilder<TEntity> : SelectBuilder<SelectEntityBuilder<TEntity>>, IStatementBuilder, IQueryBuilder, IWhereEntityBuilder<TEntity, SelectEntityBuilder<TEntity>> where TEntity : class

Type Parameters

TEntity

The type of the entity.

Inheritance
SelectEntityBuilder<TEntity>
Implements
Inherited Members

Constructors

SelectEntityBuilder(IQueryGenerator, List<QueryParameter>, LogicalOperators)

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

public SelectEntityBuilder(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.

Methods

Aggregate<TValue>(Expression<Func<TEntity, TValue>>, AggregateFunctions, string, string)

Adds an aggregate expression using the specified function and entity property.

public SelectEntityBuilder<TEntity> Aggregate<TValue>(Expression<Func<TEntity, TValue>> property, AggregateFunctions function, string tableAlias = null, string columnAlias = null)

Parameters

property Expression<Func<TEntity, TValue>>

An expression selecting the property to aggregate.

function AggregateFunctions

The aggregate function to use (e.g., Sum).

tableAlias string

The alias of the table (optional).

columnAlias string

The alias for the column (optional).

Returns

SelectEntityBuilder<TEntity>

The same builder instance for method chaining.

Type Parameters

TValue

The type of the property value.

BuildStatement()

Builds the SQL SELECT statement using the current configuration.

public override QueryStatement BuildStatement()

Returns

QueryStatement

A QueryStatement containing the SQL SELECT statement and its parameters.

Column(Expression<Func<TEntity, object>>, string, string)

Adds a column expression for the specified entity property.

public SelectEntityBuilder<TEntity> Column(Expression<Func<TEntity, object>> property, string tableAlias = null, string columnAlias = null)

Parameters

property Expression<Func<TEntity, object>>

An expression selecting the property to include in the SELECT clause.

tableAlias string

The alias of the table (optional).

columnAlias string

The alias for the column (optional).

Returns

SelectEntityBuilder<TEntity>

The same builder instance for method chaining.

ColumnIf<TValue>(Expression<Func<TEntity, TValue>>, string, string, Func<string, bool>)

Conditionally adds a column expression for the specified entity property.

public SelectEntityBuilder<TEntity> ColumnIf<TValue>(Expression<Func<TEntity, TValue>> property, string tableAlias = null, string columnAlias = null, Func<string, bool> condition = null)

Parameters

property Expression<Func<TEntity, TValue>>

An expression selecting the property to include in the SELECT clause.

tableAlias string

The alias of the table (optional).

columnAlias string

The alias for the column (optional).

condition Func<string, bool>

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

Returns

SelectEntityBuilder<TEntity>

The same builder instance for method chaining.

Type Parameters

TValue

The type of the property value.

Column<TModel>(Expression<Func<TModel, object>>, string, string)

Adds a column expression for the specified property of a model type.

public SelectEntityBuilder<TEntity> Column<TModel>(Expression<Func<TModel, object>> property, string tableAlias = null, string columnAlias = null) where TModel : class

Parameters

property Expression<Func<TModel, object>>

An expression selecting the property to include in the SELECT clause.

tableAlias string

The alias of the table (optional).

columnAlias string

The alias for the column (optional).

Returns

SelectEntityBuilder<TEntity>

The same builder instance for method chaining.

Type Parameters

TModel

The type of the model.

Columns(IEnumerable<string>, string)

Adds a column expression for each of the specified column names, using entity property mapping.

public override SelectEntityBuilder<TEntity> Columns(IEnumerable<string> columnNames, string tableAlias = null)

Parameters

columnNames IEnumerable<string>

The collection of column names to include in the SELECT clause.

tableAlias string

The alias of the table (optional).

Returns

SelectEntityBuilder<TEntity>

The same builder instance for method chaining.

Exceptions

ArgumentNullException

Thrown if columnNames is null.

Columns(string, Func<IMemberAccessor, bool>)

Adds a column expression for each property in TEntity.

public SelectEntityBuilder<TEntity> Columns(string tableAlias = null, Func<IMemberAccessor, bool> filter = null)

Parameters

tableAlias string

The alias of the table (optional).

filter Func<IMemberAccessor, bool>

An optional filter to include properties.

Returns

SelectEntityBuilder<TEntity>

The same builder instance for method chaining.

Columns<TModel>(string, Func<IMemberAccessor, bool>)

Adds a column expression for each property in TModel.

public SelectEntityBuilder<TEntity> Columns<TModel>(string tableAlias = null, Func<IMemberAccessor, bool> filter = null)

Parameters

tableAlias string

The alias of the table (optional).

filter Func<IMemberAccessor, bool>

An optional filter to include properties.

Returns

SelectEntityBuilder<TEntity>

The same builder instance for method chaining.

Type Parameters

TModel

The type of the model.

Count<TValue>(Expression<Func<TEntity, TValue>>, string, string)

Adds a COUNT aggregate expression using the specified entity property.

public SelectEntityBuilder<TEntity> Count<TValue>(Expression<Func<TEntity, TValue>> property, string tableAlias = null, string columnAlias = null)

Parameters

property Expression<Func<TEntity, TValue>>

An expression selecting the property to count.

tableAlias string

The alias of the table (optional).

columnAlias string

The alias for the column (optional).

Returns

SelectEntityBuilder<TEntity>

The same builder instance for method chaining.

Type Parameters

TValue

The type of the property value.

From(string, string, string)

Sets the target table for the SELECT statement using the entity's mapping information by default.

public override SelectEntityBuilder<TEntity> From(string tableName = null, string tableSchema = null, string tableAlias = null)

Parameters

tableName string

The name of the table (optional, defaults to entity mapping).

tableSchema string

The schema of the table (optional, defaults to entity mapping).

tableAlias string

The alias of the table (optional).

Returns

SelectEntityBuilder<TEntity>

The same builder instance for method chaining.

GroupBy<TValue>(Expression<Func<TEntity, TValue>>, string)

Adds a GROUP BY clause with the specified entity property and table alias.

public SelectEntityBuilder<TEntity> GroupBy<TValue>(Expression<Func<TEntity, TValue>> property, string tableAlias = null)

Parameters

property Expression<Func<TEntity, TValue>>

An expression selecting the property to group by.

tableAlias string

The alias of the table (optional).

Returns

SelectEntityBuilder<TEntity>

The same builder instance for method chaining.

Type Parameters

TValue

The type of the property value.

Join<TRight>(Action<JoinEntityBuilder<TEntity, TRight>>)

Adds a JOIN clause to the SELECT statement using the specified builder action for the right entity.

public SelectEntityBuilder<TEntity> Join<TRight>(Action<JoinEntityBuilder<TEntity, TRight>> builder) where TRight : class

Parameters

builder Action<JoinEntityBuilder<TEntity, TRight>>

An action that configures the join using a JoinEntityBuilder<TLeft, TRight>.

Returns

SelectEntityBuilder<TEntity>

The same builder instance for method chaining.

Type Parameters

TRight

The type of the right join entity.

Join<TLeft, TRight>(Action<JoinEntityBuilder<TLeft, TRight>>)

Adds a JOIN clause to the SELECT statement using the specified builder action for the left and right entities.

public SelectEntityBuilder<TEntity> Join<TLeft, TRight>(Action<JoinEntityBuilder<TLeft, TRight>> builder) where TLeft : class where TRight : class

Parameters

builder Action<JoinEntityBuilder<TLeft, TRight>>

An action that configures the join using a JoinEntityBuilder<TLeft, TRight>.

Returns

SelectEntityBuilder<TEntity>

The same builder instance for method chaining.

Type Parameters

TLeft

The type of the left join entity.

TRight

The type of the right join entity.

OrderByIf<TValue>(Expression<Func<TEntity, TValue>>, SortDirections, Func<string, bool>)

Conditionally adds an ORDER BY clause with the specified entity property and sort direction.

public SelectEntityBuilder<TEntity> OrderByIf<TValue>(Expression<Func<TEntity, TValue>> property, SortDirections sortDirection = SortDirections.Ascending, Func<string, bool> condition = null)

Parameters

property Expression<Func<TEntity, TValue>>

An expression selecting the property to sort by.

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

Returns

SelectEntityBuilder<TEntity>

The same builder instance for method chaining.

Type Parameters

TValue

The type of the property value.

OrderByIf<TValue>(Expression<Func<TEntity, TValue>>, string, SortDirections, Func<string, bool>)

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

public SelectEntityBuilder<TEntity> OrderByIf<TValue>(Expression<Func<TEntity, TValue>> property, string tableAlias, SortDirections sortDirection = SortDirections.Ascending, Func<string, bool> condition = null)

Parameters

property Expression<Func<TEntity, TValue>>

An expression selecting the property 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 property name. If null, the clause is always added.

Returns

SelectEntityBuilder<TEntity>

The same builder instance for method chaining.

Type Parameters

TValue

The type of the property value.

OrderBy<TValue>(Expression<Func<TEntity, TValue>>, SortDirections)

Adds an ORDER BY clause with the specified entity property and sort direction.

public SelectEntityBuilder<TEntity> OrderBy<TValue>(Expression<Func<TEntity, TValue>> property, SortDirections sortDirection = SortDirections.Ascending)

Parameters

property Expression<Func<TEntity, TValue>>

An expression selecting the property to sort by.

sortDirection SortDirections

The sort direction (default is Ascending).

Returns

SelectEntityBuilder<TEntity>

The same builder instance for method chaining.

Type Parameters

TValue

The type of the property value.

OrderBy<TValue>(Expression<Func<TEntity, TValue>>, string, SortDirections)

Adds an ORDER BY clause with the specified entity property, sort direction, and table alias.

public SelectEntityBuilder<TEntity> OrderBy<TValue>(Expression<Func<TEntity, TValue>> property, string tableAlias, SortDirections sortDirection = SortDirections.Ascending)

Parameters

property Expression<Func<TEntity, TValue>>

An expression selecting the property to sort by.

tableAlias string

The alias of the table (optional).

sortDirection SortDirections

The sort direction (default is Ascending).

Returns

SelectEntityBuilder<TEntity>

The same builder instance for method chaining.

Type Parameters

TValue

The type of the property value.

WhereAnd(Action<LogicalEntityBuilder<TEntity>>)

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

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

Parameters

builder Action<LogicalEntityBuilder<TEntity>>

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

Returns

SelectEntityBuilder<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 SelectEntityBuilder<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

SelectEntityBuilder<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 SelectEntityBuilder<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

SelectEntityBuilder<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 SelectEntityBuilder<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

SelectEntityBuilder<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 SelectEntityBuilder<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

SelectEntityBuilder<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 SelectEntityBuilder<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

SelectEntityBuilder<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 SelectEntityBuilder<TEntity> WhereOr(Action<LogicalEntityBuilder<TEntity>> builder)

Parameters

builder Action<LogicalEntityBuilder<TEntity>>

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

Returns

SelectEntityBuilder<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 SelectEntityBuilder<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

SelectEntityBuilder<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 SelectEntityBuilder<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

SelectEntityBuilder<TEntity>

The builder instance for chaining further calls.

Type Parameters

TValue

The type of the value to compare.

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

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

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

Parameters

property Expression<Func<TModel, TValue>>

An expression selecting the property to filter on.

parameterValue TValue

The value to compare the property against.

tableAlias string

The alias of the table (optional).

filterOperator FilterOperators

The filter operator to use (default is Equal).

Returns

SelectEntityBuilder<TEntity>

The same builder instance for method chaining.

Type Parameters

TModel

The type of the model.

TValue

The type of the value to compare.