Table of Contents

Class StatementBuilder<TBuilder>

Namespace
FluentCommand.Query
Assembly
FluentCommand.dll

Provides a base class for building SQL query statements, supporting tagging, comments, and parameter management.

public abstract class StatementBuilder<TBuilder> : IStatementBuilder, IQueryBuilder where TBuilder : StatementBuilder<TBuilder>

Type Parameters

TBuilder

The type of the builder for fluent chaining.

Inheritance
StatementBuilder<TBuilder>
Implements
Derived
Inherited Members

Constructors

StatementBuilder(IQueryGenerator, List<QueryParameter>)

Initializes a new instance of the StatementBuilder<TBuilder> class.

protected StatementBuilder(IQueryGenerator queryGenerator, List<QueryParameter> parameters)

Parameters

queryGenerator IQueryGenerator

The IQueryGenerator used to generate SQL expressions and comments.

parameters List<QueryParameter>

The initial list of QueryParameter objects for the query.

Exceptions

ArgumentNullException

Thrown if queryGenerator or parameters is null.

Properties

CommentExpressions

Gets or sets the list of comment expressions to be included in the query.

protected List<string> CommentExpressions { get; set; }

Property Value

List<string>

The list of comment expressions.

Parameters

Gets the list of QueryParameter objects used in the query.

protected List<QueryParameter> Parameters { get; }

Property Value

List<QueryParameter>

The list of query parameters.

QueryGenerator

Gets the IQueryGenerator used to generate SQL expressions and comments.

protected IQueryGenerator QueryGenerator { get; }

Property Value

IQueryGenerator

The IQueryGenerator instance.

Methods

BuildStatement()

Builds and returns a QueryStatement representing the SQL query and its parameters.

public abstract QueryStatement BuildStatement()

Returns

QueryStatement

A QueryStatement containing the SQL statement and associated QueryParameter values.

Comment(string)

Adds a custom comment to the query.

public TBuilder Comment(string comment)

Parameters

comment string

The comment text to add.

Returns

TBuilder

The current builder instance for method chaining.

NextParameter()

Generates the next unique parameter name for use in the query.

protected string NextParameter()

Returns

string

A unique parameter name as a string (e.g., "@p0001").

Tag(string, string, string, int)

Tags the query with a comment that includes the specified text, caller member name, source file, and line number.

public TBuilder Tag(string comment = "Caller", string memberName = "", string sourceFilePath = "", int sourceLineNumber = 0)

Parameters

comment string

The comment text to include in the tag. Defaults to "Caller".

memberName string

The name of the calling member. Automatically provided by the compiler.

sourceFilePath string

The source file path of the caller. Automatically provided by the compiler.

sourceLineNumber int

The line number in the source file. Automatically provided by the compiler.

Returns

TBuilder

The current builder instance for method chaining.