Table of Contents

Class InsertEntityBuilder<TEntity>

Namespace
FluentCommand.Query
Assembly
FluentCommand.dll

Provides a builder for constructing SQL INSERT statements for a specific entity type with fluent, chainable methods.

public class InsertEntityBuilder<TEntity> : InsertBuilder<InsertEntityBuilder<TEntity>>, IStatementBuilder, IQueryBuilder where TEntity : class

Type Parameters

TEntity

The type of the entity.

Inheritance
InsertEntityBuilder<TEntity>
Implements
Inherited Members

Constructors

InsertEntityBuilder(IQueryGenerator, List<QueryParameter>)

Initializes a new instance of the InsertEntityBuilder<TEntity> class.

public InsertEntityBuilder(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.

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.

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

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

The alias for the table (optional).

columnAlias string

The alias for the output column (optional).

Returns

InsertEntityBuilder<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 InsertEntityBuilder<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 insert.

parameterValue TValue

The value to insert 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

InsertEntityBuilder<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 InsertEntityBuilder<TEntity> Value<TValue>(Expression<Func<TEntity, TValue>> property, TValue parameterValue)

Parameters

property Expression<Func<TEntity, TValue>>

An expression selecting the property to insert.

parameterValue TValue

The value to insert for the property.

Returns

InsertEntityBuilder<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 InsertEntityBuilder<TEntity> Values(TEntity entity, IEnumerable<string> columnNames = null)

Parameters

entity TEntity

The entity to insert.

columnNames IEnumerable<string>

The column names to include (optional).

Returns

InsertEntityBuilder<TEntity>

The same builder instance for method chaining.

Exceptions

ArgumentNullException

Thrown if entity is null.