SelectStatementBuilder

Classes > Nimblesite.Sql.Model > SelectStatementBuilder

Builder for constructing SelectStatement instances ONLY FOR SELECT STATEMENTS!!!!

public sealed class SelectStatementBuilder

Methods

WithSelectColumns(IEnumerable<ColumnInfo>, bool)

public SelectStatementBuilder WithSelectColumns(IEnumerable<ColumnInfo> columns, bool distinct = false)

Sets the SELECT list columns

Parameters:

Name Type Description
columns ColumnInfo> The columns to select
distinct Boolean Whether to use DISTINCT

Returns: SelectStatementBuilder - This builder instance

AddSelectColumn(ColumnInfo)

public SelectStatementBuilder AddSelectColumn(ColumnInfo column)

Adds a SELECT column

Parameters:

Name Type Description
column ColumnInfo The column to add

Returns: SelectStatementBuilder - This builder instance

AddSelectColumn(string, string?, string?)

public SelectStatementBuilder AddSelectColumn(string name, string? alias = null, string? tableAlias = null)

Adds a SELECT column by name

Parameters:

Name Type Description
name String The column name
alias String The column alias
tableAlias String The table alias

Returns: SelectStatementBuilder - This builder instance

AddTable(TableInfo)

public SelectStatementBuilder AddTable(TableInfo table)

Adds a table to the FROM clause

Parameters:

Name Type Description
table TableInfo The table to add

Returns: SelectStatementBuilder - This builder instance

AddTable(string, string?)

public SelectStatementBuilder AddTable(string name, string? alias = null)

Adds a table by name

Parameters:

Name Type Description
name String The table name
alias String The table alias

Returns: SelectStatementBuilder - This builder instance

AddJoin(string, string, string, string)

public SelectStatementBuilder AddJoin(string leftTable, string rightTable, string condition, string joinType = "INNER")

Adds a join to the query

Parameters:

Name Type Description
leftTable String The left table
rightTable String The right table
condition String The join condition
joinType String The join type

Returns: SelectStatementBuilder - This builder instance

AddWhereCondition(WhereCondition)

public SelectStatementBuilder AddWhereCondition(WhereCondition condition)

Adds a WHERE condition

Parameters:

Name Type Description
condition WhereCondition The condition to add

Returns: SelectStatementBuilder - This builder instance

AddWhereCondition(string)

public SelectStatementBuilder AddWhereCondition(string condition)

Adds a WHERE condition from a string expression

Parameters:

Name Type Description
condition String The condition string to add

Returns: SelectStatementBuilder - This builder instance

AddGroupBy(IEnumerable<ColumnInfo>)

public SelectStatementBuilder AddGroupBy(IEnumerable<ColumnInfo> columns)

Adds GROUP BY columns

Parameters:

Name Type Description
columns ColumnInfo> The columns to group by

Returns: SelectStatementBuilder - This builder instance

AddOrderBy(string, string)

public SelectStatementBuilder AddOrderBy(string column, string direction)

Adds an ORDER BY item

Parameters:

Name Type Description
column String The column to order by
direction String The order direction

Returns: SelectStatementBuilder - This builder instance

WithHaving(string)

public SelectStatementBuilder WithHaving(string condition)

Sets the HAVING condition

Parameters:

Name Type Description
condition String The having condition

Returns: SelectStatementBuilder - This builder instance

WithLimit(string)

public SelectStatementBuilder WithLimit(string limit)

Sets the LIMIT

Parameters:

Name Type Description
limit String The limit value

Returns: SelectStatementBuilder - This builder instance

WithOffset(string)

public SelectStatementBuilder WithOffset(string offset)

Sets the OFFSET

Parameters:

Name Type Description
offset String The offset value

Returns: SelectStatementBuilder - This builder instance

WithDistinct(bool)

public SelectStatementBuilder WithDistinct(bool distinct = true)

Sets whether to use DISTINCT

Parameters:

Name Type Description
distinct Boolean Whether to use DISTINCT

Returns: SelectStatementBuilder - This builder instance

AddUnion(string, bool)

public SelectStatementBuilder AddUnion(string query, bool isUnionAll = false)

Adds a UNION operation

Parameters:

Name Type Description
query String The query to union with
isUnionAll Boolean Whether this is UNION ALL

Returns: SelectStatementBuilder - This builder instance

AddParameter(ParameterInfo)

public SelectStatementBuilder AddParameter(ParameterInfo parameter)

Adds a parameter

Parameters:

Name Type Description
parameter ParameterInfo The parameter to add

Returns: SelectStatementBuilder - This builder instance

AddParameter(string, string)

public SelectStatementBuilder AddParameter(string name, string sqlType = "NVARCHAR")

Adds a parameter by name and type

Parameters:

Name Type Description
name String The parameter name
sqlType String The SQL type

Returns: SelectStatementBuilder - This builder instance

Build()

public SelectStatement Build()

Builds the SelectStatement

Returns: SelectStatement - The constructed SelectStatement