Interface IQueryBuilder
Supplies a query's values from code instead of a parameter object. You set variables and switch conditional parts on or off, then run the command from the builder. Use it when values come from branching C# logic instead of one parameter object.
public interface IQueryBuilder
- Extension Methods
Remarks
A query is a set of optional pieces. Nothing is included until you ask for it. A variable is a piece
that carries a value (a @name parameter). A condition is a piece that only turns on or off (a
conditional marker or a projected column), it carries no data. Both are addressed by name or, once you
know it, by index.
Properties
this[int]
The value set for the variable or condition at ind, or null
when it is off.
object? this[int ind] { get; }
Parameters
indint
Property Value
this[ReadOnlySpan<char>]
The value set for the named variable or condition, or null when it is off.
object? this[ReadOnlySpan<char> condition] { get; }
Parameters
conditionReadOnlySpan<char>
Property Value
this[string]
The value set for the named variable or condition, or null when it is off.
object? this[string condition] { get; }
Parameters
conditionstring
Property Value
Methods
GetQueryText()
The SQL text for the current state, with the off pieces dropped. Reads the state alone and touches no command, so you can inspect what a run would send without executing it.
string GetQueryText()
Returns
Remove(ReadOnlySpan<char>)
Turns off the named variable or condition so its part drops from the query.
void Remove(ReadOnlySpan<char> condition)
Parameters
conditionReadOnlySpan<char>The variable or condition name.
Remove(string)
Turns off the named variable or condition so its part drops from the query.
void Remove(string condition)
Parameters
conditionstringThe variable or condition name.
Reset()
Turns everything off, back to the state of a fresh builder.
void Reset()
UnUse(int)
Turns off the condition at conditionIndex.
void UnUse(int conditionIndex)
Parameters
conditionIndexintThe condition index.
UnUse(ReadOnlySpan<char>)
Turns off a condition previously turned on with Use(string).
bool UnUse(ReadOnlySpan<char> condition)
Parameters
conditionReadOnlySpan<char>The condition name.
Returns
UnUse(string)
Turns off a condition previously turned on with Use(string).
bool UnUse(string condition)
Parameters
conditionstringThe condition name.
Returns
Use(char, string, object?)
Sets a variable to value and turns it on, spelling the variable character apart
from the name so the name can come from nameof.
bool Use(char charVariable, string variable, object? value)
Parameters
charVariablecharThe variable character the query uses, such as
@.variablestringThe variable name, without the leading character.
valueobjectThe value to bind.
Returns
Use(int)
Turns on the condition at conditionIndex.
void Use(int conditionIndex)
Parameters
conditionIndexintThe condition index.
Use(int, object?)
Sets the variable at variableIndex to value.
void Use(int variableIndex, object? value)
Parameters
Use(ReadOnlySpan<char>)
Turns on a condition, a piece that carries no value (a conditional marker or a projected column).
bool Use(ReadOnlySpan<char> condition)
Parameters
conditionReadOnlySpan<char>The condition name.
Returns
- bool
true if the name is a condition and was turned on, false if it names a value-carrying variable instead.
Use(ReadOnlySpan<char>, object?)
Sets a variable to value and turns it on. A null value turns it off.
bool Use(ReadOnlySpan<char> variable, object? value)
Parameters
variableReadOnlySpan<char>The variable name.
valueobjectThe value to bind.
Returns
Use(string)
Turns on a condition, a piece that carries no value (a conditional marker or a projected column).
bool Use(string condition)
Parameters
conditionstringThe condition name.
Returns
- bool
true if the name is a condition and was turned on, false if it names a value-carrying variable instead.
Use(string, object?)
Sets a variable to value and turns it on. A null value turns it off.
bool Use(string variable, object? value)
Parameters
Returns
UseWith(object)
Copies usable values from a parameter object into the builder.
void UseWith(object parameterObject)
Parameters
parameterObjectobject
UseWith<T>(T)
Copies usable values from a parameter object into the builder.
void UseWith<T>(T parameterObject) where T : notnull
Parameters
parameterObjectT
Type Parameters
T
UseWith<T>(ref T)
Copies usable values from a parameter object into the builder.
void UseWith<T>(ref T parameterObject) where T : notnull
Parameters
parameterObjectT
Type Parameters
T