Class UpdateBuilder<TBuilder>
- Namespace
- FluentCommand.Query
- Assembly
- FluentCommand.dll
Provides a generic base class for building SQL UPDATE statements with fluent, chainable methods.
public abstract class UpdateBuilder<TBuilder> : WhereBuilder<TBuilder>, IStatementBuilder, IQueryBuilder where TBuilder : UpdateBuilder<TBuilder>
Type Parameters
TBuilder
The type of the builder for fluent chaining.
- Inheritance
-
StatementBuilder<TBuilder>WhereBuilder<TBuilder>UpdateBuilder<TBuilder>
- Implements
- Derived
- Inherited Members
Constructors
UpdateBuilder(IQueryGenerator, List<QueryParameter>, LogicalOperators)
Initializes a new instance of the UpdateBuilder<TBuilder> class.
protected UpdateBuilder(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.
Properties
FromExpressions
Gets the collection of FROM table expressions for the UPDATE statement.
protected HashSet<TableExpression> FromExpressions { get; }
Property Value
- HashSet<TableExpression>
A HashSet<T> containing the FROM table expressions.
JoinExpressions
Gets the collection of JOIN expressions for the UPDATE statement.
protected HashSet<JoinExpression> JoinExpressions { get; }
Property Value
- HashSet<JoinExpression>
A HashSet<T> containing the JOIN expressions.
OutputExpressions
Gets the collection of output column expressions for the UPDATE statement.
protected HashSet<ColumnExpression> OutputExpressions { get; }
Property Value
- HashSet<ColumnExpression>
A HashSet<T> containing the output column expressions.
TableExpression
Gets the target table expression for the UPDATE statement.
protected TableExpression TableExpression { get; }
Property Value
- TableExpression
The TableExpression representing the target table.
UpdateExpressions
Gets the collection of update expressions for the UPDATE statement.
protected HashSet<UpdateExpression> UpdateExpressions { get; }
Property Value
- HashSet<UpdateExpression>
A HashSet<T> containing the update expressions.
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)
Adds a FROM clause to the UPDATE statement.
public virtual TBuilder From(string tableName, string tableSchema = null, string tableAlias = null)
Parameters
tableName
stringThe name of the table to include in the FROM clause.
tableSchema
stringThe schema of the table (optional).
tableAlias
stringThe alias for the table (optional).
Returns
- TBuilder
The same builder instance for method chaining.
FromRaw(string)
Adds a raw FROM clause to the UPDATE statement.
public TBuilder FromRaw(string fromClause)
Parameters
fromClause
stringThe raw SQL FROM clause.
Returns
- TBuilder
The same builder instance for method chaining.
Join(Action<JoinBuilder>)
Adds a JOIN clause to the UPDATE statement using the specified builder action.
public TBuilder Join(Action<JoinBuilder> builder)
Parameters
builder
Action<JoinBuilder>An action that configures the join using a JoinBuilder.
Returns
- TBuilder
The same builder instance for method chaining.
Output(IEnumerable<string>, string)
Adds an OUTPUT clause for the specified column names.
public TBuilder Output(IEnumerable<string> columnNames, string tableAlias = null)
Parameters
columnNames
IEnumerable<string>The collection of column names to include in the OUTPUT clause.
tableAlias
stringThe alias for the table (optional).
Returns
- TBuilder
The same builder instance for method chaining.
Exceptions
- ArgumentNullException
Thrown if
columnNames
isnull
.
Output(string, string, string)
Adds an OUTPUT clause for the specified column name.
public TBuilder Output(string columnName, string tableAlias = null, string columnAlias = null)
Parameters
columnName
stringThe name of the column to include in the OUTPUT clause.
tableAlias
stringThe alias for the table (optional).
columnAlias
stringThe alias for the output column (optional).
Returns
- TBuilder
The same builder instance for method chaining.
OutputIf(string, string, string, Func<string, bool>)
Conditionally adds an OUTPUT clause for the specified column name if the condition is met.
public TBuilder OutputIf(string columnName, string tableAlias = null, string columnAlias = null, Func<string, bool> condition = null)
Parameters
columnName
stringThe name of the column to include in the OUTPUT clause.
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
- TBuilder
The same builder instance for method chaining.
Table(string, string, string)
Sets the target table to update.
public TBuilder Table(string tableName, string tableSchema = null, string tableAlias = null)
Parameters
tableName
stringThe name of the table.
tableSchema
stringThe schema of the table (optional).
tableAlias
stringThe alias for the table (optional).
Returns
- TBuilder
The same builder instance for method chaining.
Value(string, object, Type)
Adds a value for the specified column name, value, and type.
public TBuilder Value(string columnName, object parameterValue, Type parameterType)
Parameters
columnName
stringThe name of the column to update.
parameterValue
objectThe value to set for the column.
parameterType
TypeThe type of the parameter value.
Returns
- TBuilder
The same builder instance for method chaining.
Exceptions
- ArgumentException
Thrown if
columnName
is null or empty.
ValueIf<TValue>(string, TValue, Func<string, TValue, bool>)
Conditionally adds a value for the specified column name and value if the condition is met.
public TBuilder ValueIf<TValue>(string columnName, TValue parameterValue, Func<string, TValue, bool> condition)
Parameters
columnName
stringThe name of the column to update.
parameterValue
TValueThe value to set for the column.
condition
Func<string, TValue, bool>A function that determines whether to add the value, based on the column name and value. If
null
, the value is always added.
Returns
- TBuilder
The same builder instance for method chaining.
Type Parameters
TValue
The type of the value.
Value<TValue>(string, TValue)
Adds a value for the specified column name and value.
public TBuilder Value<TValue>(string columnName, TValue parameterValue)
Parameters
columnName
stringThe name of the column to update.
parameterValue
TValueThe value to set for the column.
Returns
- TBuilder
The same builder instance for method chaining.
Type Parameters
TValue
The type of the value.