Table of Contents

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

The 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 string

The name of the table.

tableSchema string

The schema of the table (optional).

tableAlias string

The 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 string

The alias for the table (optional).

Returns

TBuilder

The same builder instance for method chaining.

Exceptions

ArgumentNullException

Thrown if columnNames is null.

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 string

The name of the column to include in the OUTPUT clause.

tableAlias string

The alias for the table (optional).

columnAlias string

The 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 string

The name of the column to include in the OUTPUT clause.

tableAlias string

The alias for the table (optional).

columnAlias string

The 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 string

The name of the column.

parameterValue object

The value to insert for the column.

parameterType Type

The 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 is null.

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 string

The name of the column.

parameterValue TValue

The 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 string

The name of the column.

parameterValue TValue

The value to insert for the column.

Returns

TBuilder

The same builder instance for method chaining.

Type Parameters

TValue

The type of the value.