Table of Contents

Class Builder

Namespace
Dapper.SimpleSqlBuilder
Assembly
Dapper.SimpleSqlBuilder.dll

An abstract class that implements the ISqlBuilder and defines the builder type.

public abstract class Builder : ISqlBuilder

Inheritance

Implements

Properties

ParameterNames

Gets the parameter names.

public abstract IEnumerable<string> ParameterNames { get; }

Property Value

IEnumerable<string>

Parameters

Gets the DynamicParameters list.

public abstract object Parameters { get; }

Property Value

object

Sql

Gets the generated the SQL.

public abstract string Sql { get; }

Property Value

string

Methods

AddDynamicParameters(object?)

Appends an object containing parameters to the dynamic parameters bag.

Example 1:

// Add property A and B to the builder.
AddDynamicParameters(new {A = 1, B = 2});

Example 2:

// Create a DynamicParameters object to hold the parameters.
var dynamicParameters = new DynamicParameters();
// Add parameters A and B to the dynamicParameters object.
dynamicParameters.Add("A", 1);
dynamicParameters.Add("B", 2);
// Add the dynamicParameters object to the builder.
AddDynamicParameters(dynamicParameters);

public abstract Builder AddDynamicParameters(object? parameter)

Parameters

parameter object?

The parameter.

Returns

Builder

The Builder instance.

AddParameter(string, object?, DbType?, ParameterDirection?, int?, byte?, byte?)

Adds a parameter to the dynamic parameters list.

public abstract Builder AddParameter(string name, object? value = null, DbType? dbType = null, ParameterDirection? direction = null, int? size = null, byte? precision = null, byte? scale = null)

Parameters

name string

The name of the parameter.

value object?

The value of the parameter.

dbType DbType?

The DbType of the parameter.

direction ParameterDirection?

The in or out ParameterDirection of the parameter.

size int?

The size of the parameter.

precision byte?

The precision of the parameter.

scale byte?

The scale of the parameter.

Returns

Builder

The Builder instance.

Append(ref AppendInterpolatedStringHandler)

Appends a space and the interpolated string to the builder.

public abstract Builder Append(ref AppendInterpolatedStringHandler handler)

Parameters

handler AppendInterpolatedStringHandler

The handler for the interpolated string.

Returns

Builder

The Builder instance.

Append(bool, ref AppendInterpolatedStringHandler)

Appends a space and the interpolated string to the builder.

public abstract Builder Append(bool condition, ref AppendInterpolatedStringHandler handler)

Parameters

condition bool

The value to determine whether the method should be executed.

handler AppendInterpolatedStringHandler

The handler for the interpolated string.

Returns

Builder

The Builder instance.

AppendIntact(ref AppendIntactInterpolatedStringHandler)

Appends the interpolated string to the builder.

public abstract Builder AppendIntact(ref AppendIntactInterpolatedStringHandler handler)

Parameters

handler AppendIntactInterpolatedStringHandler

The handler for the interpolated string.

Returns

Builder

The Builder instance.

AppendIntact(bool, ref AppendIntactInterpolatedStringHandler)

Appends the interpolated string to the builder.

public abstract Builder AppendIntact(bool condition, ref AppendIntactInterpolatedStringHandler handler)

Parameters

condition bool

The value to determine whether the method should be executed.

handler AppendIntactInterpolatedStringHandler

The handler for the interpolated string.

Returns

Builder

The Builder instance.

AppendNewLine(ref AppendNewLineInterpolatedStringHandler)

Appends a NewLine and the interpolated string to the builder.

public abstract Builder AppendNewLine(ref AppendNewLineInterpolatedStringHandler handler)

Parameters

handler AppendNewLineInterpolatedStringHandler

The handler for the interpolated string.

Returns

Builder

The Builder instance.

AppendNewLine(bool, ref AppendNewLineInterpolatedStringHandler)

Appends a NewLine and the interpolated string to the builder.

public abstract Builder AppendNewLine(bool condition, ref AppendNewLineInterpolatedStringHandler handler)

Parameters

condition bool

The value to determine whether the method should be executed.

handler AppendNewLineInterpolatedStringHandler

The handler for the interpolated string.

Returns

Builder

The Builder instance.

AppendNewLine()

Appends a NewLine to the builder.

public abstract Builder AppendNewLine()

Returns

Builder

The Builder instance.

GetValue<T>(string)

Gets the value of a parameter.

public abstract T GetValue<T>(string parameterName)

Parameters

parameterName string

The name of the parameter.

Returns

T

The value of the parameter. Note DBNull.Value is not returned, instead the value is returned as null.

Type Parameters

T

The type to cast the value to.

Reset()

Resets the builder to its initial state.

This resets the parameters and the SQL string.

public abstract void Reset()

Operators

operator +(Builder, FormattableString)

An add operator for the builder that enables dynamic query concatenation.

public static Builder operator +(Builder builder, FormattableString formattable)

Parameters

builder Builder

The Builder instance to perform the operation on.

formattable FormattableString

The FormattableString.

Returns

Builder

The Builder instance.

Exceptions

ArgumentNullException

Throws an ArgumentNullException when called on a null object.