Class InsertBuilder<TBuilder>
- Namespace
- FluentCommand.Query
- Assembly
- FluentCommand.dll
Provides a generic base class for building SQL INSERT statements with fluent, chainable methods.
public abstract class InsertBuilder<TBuilder> : StatementBuilder<TBuilder>, IStatementBuilder, IQueryBuilder where TBuilder : InsertBuilder<TBuilder>
Type Parameters
TBuilder
The type of the builder for fluent chaining.
- Inheritance
-
StatementBuilder<TBuilder>InsertBuilder<TBuilder>
- Implements
- Derived
- Inherited Members
Constructors
InsertBuilder(IQueryGenerator, List<QueryParameter>)
Initializes a new instance of the InsertBuilder<TBuilder> class.
protected InsertBuilder(IQueryGenerator queryGenerator, List<QueryParameter> parameters)
Parameters
queryGenerator
IQueryGeneratorThe IQueryGenerator used to generate SQL expressions.
parameters
List<QueryParameter>The list of QueryParameter objects for the query.
Properties
ColumnExpressions
Gets the collection of column expressions for the INSERT statement.
protected HashSet<ColumnExpression> ColumnExpressions { get; }
Property Value
- HashSet<ColumnExpression>
A HashSet<T> containing the column expressions.
OutputExpressions
Gets the collection of output column expressions for the INSERT 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 INSERT statement.
protected TableExpression TableExpression { get; }
Property Value
- TableExpression
The TableExpression representing the target table.
ValueExpressions
Gets the collection of value expressions for the INSERT statement.
protected HashSet<string> ValueExpressions { get; }
Property Value
- HashSet<string>
A HashSet<T> containing the value expressions (parameter names).
Methods
BuildStatement()
Builds the SQL INSERT statement using the current configuration.
public override QueryStatement BuildStatement()
Returns
- QueryStatement
A QueryStatement containing the SQL INSERT statement and its parameters.
Into(string, string, string)
Sets the target table to insert into.
public TBuilder Into(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.
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.
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.
parameterValue
objectThe value to insert 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.- ArgumentNullException
Thrown if
parameterType
isnull
.
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.
parameterValue
TValueThe value to insert 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.
parameterValue
TValueThe value to insert for the column.
Returns
- TBuilder
The same builder instance for method chaining.
Type Parameters
TValue
The type of the value.