Table of Contents

Class QueryBuilder

Namespace
Cuemon.Data
Assembly
Cuemon.Data.dll

An abstract class for building T-SQL statements from table and columns definitions.

public abstract class QueryBuilder
Inheritance
QueryBuilder
Derived

Constructors

QueryBuilder()

Initializes a new instance of the QueryBuilder class.

protected QueryBuilder()

QueryBuilder(String, IDictionary<String, String>)

Initializes a new instance of the QueryBuilder class.

protected QueryBuilder(string tableName, IDictionary<string, string> keyColumns)

Parameters

tableName String

The name of the table or view.

keyColumns IDictionary<String, String>

The key columns to be used in this QueryBuilder instance.

QueryBuilder(String, IDictionary<String, String>, IDictionary<String, String>)

Initializes a new instance of the QueryBuilder class.

protected QueryBuilder(string tableName, IDictionary<string, string> keyColumns, IDictionary<string, string> columns)

Parameters

tableName String

The name of the table or view.

keyColumns IDictionary<String, String>

The key columns to be used in this QueryBuilder instance.

columns IDictionary<String, String>

The none-key columns to be used in this QueryBuilder instance.

Properties

Columns

Gets the none-key columns to be used in the QueryBuilder instance.

public IDictionary<string, string> Columns { get; }

Property Value

IDictionary<String, String>

The none-key columns to be used in the QueryBuilder instance.

EnableDirtyReads

Gets or sets a value indicating whether the data source should try to prevent locking from readonly queries.

public bool EnableDirtyReads { get; set; }

Property Value

Boolean

true if the data source should try to prevent locking from readonly queries; otherwise, false.

EnableReadLimit

Gets or sets a value indicating whether a query is restricted in how many records (ReadLimit) can be retrieved from a repository. Default is false.

public bool EnableReadLimit { get; set; }

Property Value

Boolean

true if a query is restricted in how many records (ReadLimit) can be retrieved from a repository; otherwise, false.

EnableTableAndColumnEncapsulation

Gets or sets a value indicating whether an encapsulation should be committed automatically on table and column names.

public bool EnableTableAndColumnEncapsulation { get; set; }

Property Value

Boolean

true if an encapsulation should be committed automatically on table and column names; otherwise, false.

KeyColumns

Gets the key columns to be used in the QueryBuilder instance.

public IDictionary<string, string> KeyColumns { get; }

Property Value

IDictionary<String, String>

The key columns to be used in the QueryBuilder instance.

ReadLimit

Gets or sets a value limiting the maximum amount of records that can be retrieved from a repository. Default is 1000.

public int ReadLimit { get; set; }

Property Value

Int32

The maximum amount of records that can be retrieved from a repository.

TableName

Gets or sets the name of the table or view.

public string TableName { get; set; }

Property Value

String

The name of the table or view.

Methods

Append(String)

Appends the specified query fragment to the end of this instance.

protected QueryBuilder Append(string queryFragment)

Parameters

queryFragment String

The query fragment to append.

Returns

QueryBuilder

A reference to this instance after the operation has completed.

Append(String, Object[])

Appends a formatted query fragment, which contains zero or more format specifications, to the end of this instance. Each format specification is replaced by the string representation of a corresponding object argument.

protected QueryBuilder Append(string queryFragment, params object[] args)

Parameters

queryFragment String

The query fragment to append.

args Object[]

An array of objects to format.

Returns

QueryBuilder

A reference to this instance after the operation has completed.

EncodeFragment(QueryFormat, IEnumerable<String>, Boolean)

Encodes the specified sequence of values into the desired format of fragments.

public static string EncodeFragment(QueryFormat format, IEnumerable<string> values, bool distinct = false)

Parameters

format QueryFormat

One of the enumeration values that specifies the fragment to produce.

values IEnumerable<String>

The IEnumerable<T> to convert into the desired format of fragments.

distinct Boolean

if set to true, values will be filtered for doublets.

Returns

String

A query fragment in the desired format.

Exceptions

ArgumentNullException

values cannot be null.

ArgumentException

values contains no elements.

GetQuery(QueryType)

Create and returns the query from the specified QueryType.

public string GetQuery(QueryType queryType)

Parameters

queryType QueryType

Type of the query to create.

Returns

String

The result of the builder as a T-SQL query.

GetQuery(QueryType, String)

Create and returns the builded query from the specified QueryType.

public abstract string GetQuery(QueryType queryType, string tableName)

Parameters

queryType QueryType

Type of the query to create.

tableName String

The name of the table or view. Overrides the class wide tableName.

Returns

String

ToString()

Returns a String that represents the current Object.

public override string ToString()

Returns

String

A String that represents the current Object.