Class UpdateEntityBuilder<TEntity>
- Namespace
- FluentCommand.Query
- Assembly
- FluentCommand.dll
Provides a builder for constructing SQL UPDATE statements for a specific entity type with fluent, chainable methods.
public class UpdateEntityBuilder<TEntity> : UpdateBuilder<UpdateEntityBuilder<TEntity>>, IStatementBuilder, IQueryBuilder, IWhereEntityBuilder<TEntity, UpdateEntityBuilder<TEntity>> where TEntity : class
Type Parameters
TEntity
The type of the entity.
- Inheritance
-
StatementBuilder<UpdateEntityBuilder<TEntity>>WhereBuilder<UpdateEntityBuilder<TEntity>>UpdateBuilder<UpdateEntityBuilder<TEntity>>UpdateEntityBuilder<TEntity>
- Implements
-
IWhereEntityBuilder<TEntity, UpdateEntityBuilder<TEntity>>
- Inherited Members
Constructors
UpdateEntityBuilder(IQueryGenerator, List<QueryParameter>, LogicalOperators)
Initializes a new instance of the UpdateEntityBuilder<TEntity> class.
public UpdateEntityBuilder(IQueryGenerator queryGenerator, List<QueryParameter> parameters, LogicalOperators logicalOperator = LogicalOperators.And)
Parameters
queryGenerator
IQueryGeneratorThe IQueryGenerator used to generate SQL expressions.
parameters
List<QueryParameter>The list of QueryParameter objects for the query.
logicalOperator
LogicalOperatorsThe logical operator (LogicalOperators) to combine WHERE expressions. Defaults to And.
Methods
BuildStatement()
Builds the SQL UPDATE statement using the current configuration.
public override QueryStatement BuildStatement()
Returns
- QueryStatement
A QueryStatement containing the SQL UPDATE statement and its parameters.
From(string, string, string)
Sets the target table for the UPDATE statement using the entity's mapping information by default.
public override UpdateEntityBuilder<TEntity> From(string tableName = null, string tableSchema = null, string tableAlias = null)
Parameters
tableName
stringThe name of the table (optional, defaults to entity mapping).
tableSchema
stringThe schema of the table (optional, defaults to entity mapping).
tableAlias
stringThe alias for the table (optional).
Returns
- UpdateEntityBuilder<TEntity>
The same builder instance for method chaining.
Join<TRight>(Action<JoinEntityBuilder<TEntity, TRight>>)
Adds a JOIN clause to the UPDATE statement using the specified builder action for the right entity.
public UpdateEntityBuilder<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
- UpdateEntityBuilder<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 UPDATE statement using the specified builder action for the left and right entities.
public UpdateEntityBuilder<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
- UpdateEntityBuilder<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.
OutputIf<TValue>(Expression<Func<TEntity, TValue>>, string, string, Func<string, bool>)
Conditionally adds an OUTPUT clause for the specified entity property if the condition is met.
public UpdateEntityBuilder<TEntity> OutputIf<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 output.
tableAlias
stringThe alias for the table (optional).
columnAlias
stringThe alias for the output column (optional).
condition
Func<string, bool>A function that determines whether to add the OUTPUT clause. If
null
, the clause is always added.
Returns
- UpdateEntityBuilder<TEntity>
The same builder instance for method chaining.
Type Parameters
TValue
The type of the property value.
Output<TValue>(Expression<Func<TEntity, TValue>>, string, string)
Adds an OUTPUT clause for the specified entity property.
public UpdateEntityBuilder<TEntity> Output<TValue>(Expression<Func<TEntity, TValue>> property, string tableAlias = null, string columnAlias = null)
Parameters
property
Expression<Func<TEntity, TValue>>An expression selecting the property to output.
tableAlias
stringThe alias for the table (optional).
columnAlias
stringThe alias for the output column (optional).
Returns
- UpdateEntityBuilder<TEntity>
The same builder instance for method chaining.
Type Parameters
TValue
The type of the property value.
ValueIf<TValue>(Expression<Func<TEntity, TValue>>, TValue, Func<string, TValue, bool>)
Conditionally adds a value for the specified entity property and value if the condition is met.
public UpdateEntityBuilder<TEntity> ValueIf<TValue>(Expression<Func<TEntity, TValue>> property, TValue parameterValue, Func<string, TValue, bool> condition)
Parameters
property
Expression<Func<TEntity, TValue>>An expression selecting the property to update.
parameterValue
TValueThe value to set for the property.
condition
Func<string, TValue, bool>A function that determines whether to add the value, based on the property name and value. If
null
, the value is always added.
Returns
- UpdateEntityBuilder<TEntity>
The same builder instance for method chaining.
Type Parameters
TValue
The type of the value.
Value<TValue>(Expression<Func<TEntity, TValue>>, TValue)
Adds a value for the specified entity property and value.
public UpdateEntityBuilder<TEntity> Value<TValue>(Expression<Func<TEntity, TValue>> property, TValue parameterValue)
Parameters
property
Expression<Func<TEntity, TValue>>An expression selecting the property to update.
parameterValue
TValueThe value to set for the property.
Returns
- UpdateEntityBuilder<TEntity>
The same builder instance for method chaining.
Type Parameters
TValue
The type of the value.
Values(TEntity, IEnumerable<string>)
Adds values from the specified entity. If column names are provided, only those that match an entity property name will be included.
public UpdateEntityBuilder<TEntity> Values(TEntity entity, IEnumerable<string> columnNames = null)
Parameters
entity
TEntityThe entity to update.
columnNames
IEnumerable<string>The column names to include (optional).
Returns
- UpdateEntityBuilder<TEntity>
The same builder instance for method chaining.
Exceptions
- ArgumentNullException
Thrown if
entity
isnull
.
WhereAnd(Action<LogicalEntityBuilder<TEntity>>)
Adds a logical AND group to the WHERE clause using the specified builder action.
public UpdateEntityBuilder<TEntity> WhereAnd(Action<LogicalEntityBuilder<TEntity>> builder)
Parameters
builder
Action<LogicalEntityBuilder<TEntity>>An action that configures the logical AND group using a LogicalEntityBuilder<TEntity>.
Returns
- UpdateEntityBuilder<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 UpdateEntityBuilder<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
TValueThe value to compare the property against.
filterOperator
FilterOperatorsThe 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
- UpdateEntityBuilder<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 UpdateEntityBuilder<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
TValueThe value to compare the property against.
tableAlias
stringThe table alias to use in the query.
filterOperator
FilterOperatorsThe 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
- UpdateEntityBuilder<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 UpdateEntityBuilder<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
- UpdateEntityBuilder<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 UpdateEntityBuilder<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
stringThe 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
- UpdateEntityBuilder<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 UpdateEntityBuilder<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
stringThe table alias to use in the query (optional).
Returns
- UpdateEntityBuilder<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 UpdateEntityBuilder<TEntity> WhereOr(Action<LogicalEntityBuilder<TEntity>> builder)
Parameters
builder
Action<LogicalEntityBuilder<TEntity>>An action that configures the logical OR group using a LogicalEntityBuilder<TEntity>.
Returns
- UpdateEntityBuilder<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 UpdateEntityBuilder<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
TValueThe value to compare the property against.
filterOperator
FilterOperatorsThe filter operator to use (default is Equal).
Returns
- UpdateEntityBuilder<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 UpdateEntityBuilder<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
TValueThe value to compare the property against.
tableAlias
stringThe table alias to use in the query.
filterOperator
FilterOperatorsThe filter operator to use (default is Equal).
Returns
- UpdateEntityBuilder<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 UpdateEntityBuilder<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
TValueThe value to compare the property against.
tableAlias
stringThe alias of the table (optional).
filterOperator
FilterOperatorsThe filter operator to use (default is Equal).
Returns
- UpdateEntityBuilder<TEntity>
The same builder instance for method chaining.
Type Parameters
TModel
The type of the model.
TValue
The type of the value to compare.