Class QueryBuilder
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
tableNamestringThe name of the table or view.
keyColumnsIDictionary<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
tableNamestringThe name of the table or view.
keyColumnsIDictionary<string, string>The key columns to be used in this QueryBuilder instance.
columnsIDictionary<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
- bool
trueif 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
- bool
trueif 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
- bool
trueif 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
- int
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
queryFragmentstringThe query fragment to append.
Returns
- QueryBuilder
A reference to this instance after the operation has completed.
Append(string, params 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
Returns
- QueryBuilder
A reference to this instance after the operation has completed.
EncodeFragment(QueryFormat, IEnumerable<string>, bool)
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
formatQueryFormatOne of the enumeration values that specifies the fragment to produce.
valuesIEnumerable<string>The IEnumerable<T> to convert into the desired
formatof fragments.distinctboolif set to
true,valueswill be filtered for doublets.
Returns
- string
A query fragment in the desired format.
Exceptions
- ArgumentNullException
valuescannot be null.- ArgumentException
valuescontains no elements.
GetQuery(QueryType)
Create and returns the query from the specified QueryType.
public string GetQuery(QueryType queryType)
Parameters
queryTypeQueryTypeType 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
queryTypeQueryTypeType of the query to create.
tableNamestringThe name of the table or view. Overrides the class wide tableName.
Returns
ToString()
public override string ToString()