Table of Contents

Method AddParam

Namespace
Open.Database.Extensions
Assembly
Open.Database.Extensions.Core.dll

AddParam(Param)

Adds a parameter to the params list.

protected TThis AddParam(ExpressiveCommandBase<TConnection, TCommand, TReader, TDbType, TThis>.Param param)

Parameters

param ExpressiveCommandBase<TConnection, TCommand, TReader, TDbType, TThis>.Param

The parameter to add.

Returns

TThis

This instance for use in method chaining.

AddParam(string, object?, TDbType, ParameterDirection)

Adds a parameter to the params list.

public TThis AddParam(string name, object? value, TDbType type, ParameterDirection direction = ParameterDirection.Input)

Parameters

name string

The name of the parameter.

value object

The value of the parameter.

type TDbType

The database type of the parameter.

direction ParameterDirection

The direction of the parameter.

Returns

TThis

This instance for use in method chaining.

Remarks

A null value passed to an overload whose argument has a static type (a nullable value type, or a string) is sent with the database type of that type, the same choice AddParams makes for a NULL member. A type you pass always wins. The object overloads have no type to use, and neither does a call that gives the direction by position (AddParam(name, value, ParameterDirection.Input)): pass a database type, or name the direction (direction: ...).

Exceptions

ArgumentNullException

name is null.

ArgumentException

name is empty or white space.

AddParam(string, object?, ParameterDirection)

Adds a parameter to the params list.

public TThis AddParam(string name, object? value, ParameterDirection direction = ParameterDirection.Input)

Parameters

name string

The name of the parameter.

value object

The value of the parameter.

direction ParameterDirection

The direction of the parameter.

Returns

TThis

This instance for use in method chaining.

Remarks

A null value passed to an overload whose argument has a static type (a nullable value type, or a string) is sent with the database type of that type, the same choice AddParams makes for a NULL member. A type you pass always wins. The object overloads have no type to use, and neither does a call that gives the direction by position (AddParam(name, value, ParameterDirection.Input)): pass a database type, or name the direction (direction: ...).

Exceptions

ArgumentNullException

name is null.

ArgumentException

name is empty or white space.

AddParam<T>(string, T?, TDbType?, ParameterDirection)

Adds a parameter to the params list.

public TThis AddParam<T>(string name, T? value, TDbType? type = null, ParameterDirection direction = ParameterDirection.Input) where T : struct

Parameters

name string

The name of the parameter.

value T?

The value of the parameter.

type TDbType?

The database type of the parameter.

direction ParameterDirection

The direction of the parameter.

Returns

TThis

This instance for use in method chaining.

Type Parameters

T

The type of the value.

Remarks

A null value passed to an overload whose argument has a static type (a nullable value type, or a string) is sent with the database type of that type, the same choice AddParams makes for a NULL member. A type you pass always wins. The object overloads have no type to use, and neither does a call that gives the direction by position (AddParam(name, value, ParameterDirection.Input)): pass a database type, or name the direction (direction: ...).

Exceptions

ArgumentNullException

name is null.

ArgumentException

name is empty or white space.

AddParam(string, int, TDbType?, ParameterDirection)

Adds a parameter with an int value.

public TThis AddParam(string name, int value, TDbType? type = null, ParameterDirection direction = ParameterDirection.Input)

Parameters

name string

The name of the parameter.

value int

The value of the parameter.

type TDbType?

The database type of the parameter.

direction ParameterDirection

The direction of the parameter.

Returns

TThis

This instance for use in method chaining.

Remarks

A null value passed to an overload whose argument has a static type (a nullable value type, or a string) is sent with the database type of that type, the same choice AddParams makes for a NULL member. A type you pass always wins. The object overloads have no type to use, and neither does a call that gives the direction by position (AddParam(name, value, ParameterDirection.Input)): pass a database type, or name the direction (direction: ...).

Exceptions

ArgumentNullException

name is null.

ArgumentException

name is empty or white space.

AddParam(string, long, TDbType?, ParameterDirection)

Adds a parameter with a long value.

public TThis AddParam(string name, long value, TDbType? type = null, ParameterDirection direction = ParameterDirection.Input)

Parameters

name string

The name of the parameter.

value long

The value of the parameter.

type TDbType?

The database type of the parameter.

direction ParameterDirection

The direction of the parameter.

Returns

TThis

This instance for use in method chaining.

Remarks

A null value passed to an overload whose argument has a static type (a nullable value type, or a string) is sent with the database type of that type, the same choice AddParams makes for a NULL member. A type you pass always wins. The object overloads have no type to use, and neither does a call that gives the direction by position (AddParam(name, value, ParameterDirection.Input)): pass a database type, or name the direction (direction: ...).

Exceptions

ArgumentNullException

name is null.

ArgumentException

name is empty or white space.

AddParam(string, char, TDbType?, ParameterDirection)

Adds a parameter with a char value, sent as a character.

public TThis AddParam(string name, char value, TDbType? type = null, ParameterDirection direction = ParameterDirection.Input)

Parameters

name string

The name of the parameter.

value char

The value of the parameter.

type TDbType?

The database type of the parameter.

direction ParameterDirection

The direction of the parameter.

Returns

TThis

This instance for use in method chaining.

Remarks

A null value passed to an overload whose argument has a static type (a nullable value type, or a string) is sent with the database type of that type, the same choice AddParams makes for a NULL member. A type you pass always wins. The object overloads have no type to use, and neither does a call that gives the direction by position (AddParam(name, value, ParameterDirection.Input)): pass a database type, or name the direction (direction: ...).

Exceptions

ArgumentNullException

name is null.

ArgumentException

name is empty or white space.

AddParam(string, string?, TDbType?, ParameterDirection)

Adds a parameter to the params list.

public TThis AddParam(string name, string? value, TDbType? type = null, ParameterDirection direction = ParameterDirection.Input)

Parameters

name string

The name of the parameter.

value string

The value of the parameter.

type TDbType?

The database type of the parameter.

direction ParameterDirection

The direction of the parameter.

Returns

TThis

This instance for use in method chaining.

Remarks

A null value passed to an overload whose argument has a static type (a nullable value type, or a string) is sent with the database type of that type, the same choice AddParams makes for a NULL member. A type you pass always wins. The object overloads have no type to use, and neither does a call that gives the direction by position (AddParam(name, value, ParameterDirection.Input)): pass a database type, or name the direction (direction: ...).

Exceptions

ArgumentNullException

name is null.

ArgumentException

name is empty or white space.

AddParam(string, int, TDbType, ParameterDirection)

Adds a parameter with an int value and a required database type.

public TThis AddParam(string name, int value, TDbType type, ParameterDirection direction = ParameterDirection.Input)

Parameters

name string

The name of the parameter.

value int

The value of the parameter.

type TDbType

The database type of the parameter.

direction ParameterDirection

The direction of the parameter.

Returns

TThis

This instance for use in method chaining.

Remarks

A null value passed to an overload whose argument has a static type (a nullable value type, or a string) is sent with the database type of that type, the same choice AddParams makes for a NULL member. A type you pass always wins. The object overloads have no type to use, and neither does a call that gives the direction by position (AddParam(name, value, ParameterDirection.Input)): pass a database type, or name the direction (direction: ...).

Exceptions

ArgumentNullException

name is null.

ArgumentException

name is empty or white space.

AddParam(string, long, TDbType, ParameterDirection)

Adds a parameter with a long value and a required database type.

public TThis AddParam(string name, long value, TDbType type, ParameterDirection direction = ParameterDirection.Input)

Parameters

name string

The name of the parameter.

value long

The value of the parameter.

type TDbType

The database type of the parameter.

direction ParameterDirection

The direction of the parameter.

Returns

TThis

This instance for use in method chaining.

Remarks

A null value passed to an overload whose argument has a static type (a nullable value type, or a string) is sent with the database type of that type, the same choice AddParams makes for a NULL member. A type you pass always wins. The object overloads have no type to use, and neither does a call that gives the direction by position (AddParam(name, value, ParameterDirection.Input)): pass a database type, or name the direction (direction: ...).

Exceptions

ArgumentNullException

name is null.

ArgumentException

name is empty or white space.

AddParam(string, char, TDbType, ParameterDirection)

Adds a parameter with a char value, sent as a character, and a required database type.

public TThis AddParam(string name, char value, TDbType type, ParameterDirection direction = ParameterDirection.Input)

Parameters

name string

The name of the parameter.

value char

The value of the parameter.

type TDbType

The database type of the parameter.

direction ParameterDirection

The direction of the parameter.

Returns

TThis

This instance for use in method chaining.

Remarks

A null value passed to an overload whose argument has a static type (a nullable value type, or a string) is sent with the database type of that type, the same choice AddParams makes for a NULL member. A type you pass always wins. The object overloads have no type to use, and neither does a call that gives the direction by position (AddParam(name, value, ParameterDirection.Input)): pass a database type, or name the direction (direction: ...).

Exceptions

ArgumentNullException

name is null.

ArgumentException

name is empty or white space.

AddParam(string, string?, TDbType, ParameterDirection)

Adds a parameter to the params list.

public TThis AddParam(string name, string? value, TDbType type, ParameterDirection direction = ParameterDirection.Input)

Parameters

name string

The name of the parameter.

value string

The value of the parameter.

type TDbType

The database type of the parameter.

direction ParameterDirection

The direction of the parameter.

Returns

TThis

This instance for use in method chaining.

Remarks

A null value passed to an overload whose argument has a static type (a nullable value type, or a string) is sent with the database type of that type, the same choice AddParams makes for a NULL member. A type you pass always wins. The object overloads have no type to use, and neither does a call that gives the direction by position (AddParam(name, value, ParameterDirection.Input)): pass a database type, or name the direction (direction: ...).

Exceptions

ArgumentNullException

name is null.

ArgumentException

name is empty or white space.

AddParam<T>(string, T?, TDbType, ParameterDirection)

Adds a parameter to the params list.

public TThis AddParam<T>(string name, T? value, TDbType type, ParameterDirection direction = ParameterDirection.Input) where T : struct

Parameters

name string

The name of the parameter.

value T?

The value of the parameter.

type TDbType

The database type of the parameter.

direction ParameterDirection

The direction of the parameter.

Returns

TThis

This instance for use in method chaining.

Type Parameters

T

The type of the value.

Remarks

A null value passed to an overload whose argument has a static type (a nullable value type, or a string) is sent with the database type of that type, the same choice AddParams makes for a NULL member. A type you pass always wins. The object overloads have no type to use, and neither does a call that gives the direction by position (AddParam(name, value, ParameterDirection.Input)): pass a database type, or name the direction (direction: ...).

Exceptions

ArgumentNullException

name is null.

ArgumentException

name is empty or white space.

AddParam(string, string?)

Adds an input parameter with a string value, named as you write it.

public TThis AddParam(string name, string? value)

Parameters

name string

The name of the parameter.

value string

The value of the parameter.

Returns

TThis

This instance for use in method chaining.

Remarks

A null value passed to an overload whose argument has a static type (a nullable value type, or a string) is sent with the database type of that type, the same choice AddParams makes for a NULL member. A type you pass always wins. The object overloads have no type to use, and neither does a call that gives the direction by position (AddParam(name, value, ParameterDirection.Input)): pass a database type, or name the direction (direction: ...).

Exceptions

ArgumentNullException

name is null.

ArgumentException

name is empty or white space.

AddParam(string, TDbType, ParameterDirection)

Adds a parameter to the params list.

public TThis AddParam(string name, TDbType type, ParameterDirection direction = ParameterDirection.Input)

Parameters

name string

The name of the parameter.

type TDbType

The database type of the parameter.

direction ParameterDirection

The direction of the parameter.

Returns

TThis

This instance for use in method chaining.

Remarks

A null value passed to an overload whose argument has a static type (a nullable value type, or a string) is sent with the database type of that type, the same choice AddParams makes for a NULL member. A type you pass always wins. The object overloads have no type to use, and neither does a call that gives the direction by position (AddParam(name, value, ParameterDirection.Input)): pass a database type, or name the direction (direction: ...).

Exceptions

ArgumentNullException

name is null.

ArgumentException

name is empty or white space.

AddParam(string, ParameterDirection)

Adds a parameter with no value and the direction given.

public TThis AddParam(string name, ParameterDirection direction)

Parameters

name string

The name of the parameter.

direction ParameterDirection

The direction of the parameter.

Returns

TThis

This instance for use in method chaining.

Remarks

A null value passed to an overload whose argument has a static type (a nullable value type, or a string) is sent with the database type of that type, the same choice AddParams makes for a NULL member. A type you pass always wins. The object overloads have no type to use, and neither does a call that gives the direction by position (AddParam(name, value, ParameterDirection.Input)): pass a database type, or name the direction (direction: ...).

Exceptions

ArgumentNullException

name is null.

ArgumentException

name is empty or white space.

AddParam<T>(T, string?)

Adds an input parameter whose name is taken from the argument expression: AddParam(filter.AuthorId) adds a parameter named for AuthorId.

public TThis AddParam<T>(T value, string? expression = null)

Parameters

value T

The value of the parameter. A null is sent as a database null.

expression string

The text of the argument, supplied by the compiler. Do not pass it.

Returns

TThis

This instance for use in method chaining.

Type Parameters

T

The type of the value.

Remarks

The argument must be a variable or a chain of member accesses (properties and fields alike): startDate, filter.AuthorId, post.Author.Id. Anything else (a call, an index, an operator, a literal) throws ArgumentException: use AddParam(string, object?, ParameterDirection) and name the parameter.

The name is settled when the command executes. The real parameter names are:

  • for a stored procedure, the names the provider reports for the procedure;
  • for a text command, the @name markers found in its SQL text (not those inside a string, a quoted identifier or a comment, and not @@system variables).

The argument is matched to one of them, trying in turn:

  1. exactly;
  2. ignoring case;
  3. ignoring case and underscores, so AuthorId finds @author_id;
  4. failing those, for the same argument, after removing one common parameter prefix from the real name (p_, in_, i_, prm_, par_, v_, or a lone p before a capital letter), so Author finds @p_author and @pAuthor.

A field prefix on the last member (m_, s_ or _) is also tried without. A chain tries its more specific endings first: post.Author.Id tries postAuthorId, AuthorId, then Id. A name that matches nothing, matches two parameters at one tier, or is claimed by two arguments throws InvalidOperationException that says what you wrote and, when the names are known, what the procedure declares.

The names are remembered per connection factory, pool or connection, and read again when an argument matches none of them. Nothing else triggers a read, so an ambiguity, a collision or a less specific match is decided from the remembered names.

Where the real names are not available (a text command with no @name marker, or a provider that does not supply them) the last member is used as written.

Exceptions

ArgumentException

A parameter name cannot be derived from the argument.

InvalidOperationException

When the command executes: the name matches no parameter, matches two at one tier, or collides with another argument.