Class DeleteBuilder<TBuilder>
- Namespace
- FluentCommand.Query
- Assembly
- FluentCommand.dll
Provides a generic base class for building SQL DELETE statements with fluent, chainable methods.
public abstract class DeleteBuilder<TBuilder> : WhereBuilder<TBuilder>, IStatementBuilder, IQueryBuilder where TBuilder : DeleteBuilder<TBuilder>
Type Parameters
TBuilder
The type of the builder for fluent chaining.
- Inheritance
-
StatementBuilder<TBuilder>WhereBuilder<TBuilder>DeleteBuilder<TBuilder>
- Implements
- Derived
- Inherited Members
Constructors
DeleteBuilder(IQueryGenerator, List<QueryParameter>, LogicalOperators)
Initializes a new instance of the DeleteBuilder<TBuilder> class.
protected DeleteBuilder(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 DELETE 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 DELETE 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 DELETE 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 DELETE statement.
protected TableExpression TableExpression { get; }
Property Value
- TableExpression
The TableExpression representing the target table.
Methods
BuildStatement()
Builds the SQL DELETE statement using the current configuration.
public override QueryStatement BuildStatement()
Returns
- QueryStatement
A QueryStatement containing the SQL DELETE statement and its parameters.
From(string, string, string)
Adds a FROM clause to the DELETE 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 DELETE 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 DELETE 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 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 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 delete from.
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.