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
IQueryGeneratorThe 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
orparameters
isnull
.
Properties
CommentExpressions
Gets or sets the list of comment expressions to be included in the query.
protected List<string> CommentExpressions { get; set; }
Property Value
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
stringThe 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
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
stringThe comment text to include in the tag. Defaults to "Caller".
memberName
stringThe name of the calling member. Automatically provided by the compiler.
sourceFilePath
stringThe source file path of the caller. Automatically provided by the compiler.
sourceLineNumber
intThe line number in the source file. Automatically provided by the compiler.
Returns
- TBuilder
The current builder instance for method chaining.