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
paramExpressiveCommandBase<TConnection, TCommand, TReader, TDbType, TThis>.ParamThe 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
namestringThe name of the parameter.
valueobjectThe value of the parameter.
typeTDbTypeThe database type of the parameter.
directionParameterDirectionThe 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
nameis null.- ArgumentException
nameis 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
namestringThe name of the parameter.
valueobjectThe value of the parameter.
directionParameterDirectionThe 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
nameis null.- ArgumentException
nameis 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
namestringThe name of the parameter.
valueT?The value of the parameter.
typeTDbType?The database type of the parameter.
directionParameterDirectionThe direction of the parameter.
Returns
- TThis
This instance for use in method chaining.
Type Parameters
TThe 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
nameis null.- ArgumentException
nameis 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
namestringThe name of the parameter.
valueintThe value of the parameter.
typeTDbType?The database type of the parameter.
directionParameterDirectionThe 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
nameis null.- ArgumentException
nameis 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
namestringThe name of the parameter.
valuelongThe value of the parameter.
typeTDbType?The database type of the parameter.
directionParameterDirectionThe 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
nameis null.- ArgumentException
nameis 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
namestringThe name of the parameter.
valuecharThe value of the parameter.
typeTDbType?The database type of the parameter.
directionParameterDirectionThe 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
nameis null.- ArgumentException
nameis 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
namestringThe name of the parameter.
valuestringThe value of the parameter.
typeTDbType?The database type of the parameter.
directionParameterDirectionThe 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
nameis null.- ArgumentException
nameis 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
namestringThe name of the parameter.
valueintThe value of the parameter.
typeTDbTypeThe database type of the parameter.
directionParameterDirectionThe 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
nameis null.- ArgumentException
nameis 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
namestringThe name of the parameter.
valuelongThe value of the parameter.
typeTDbTypeThe database type of the parameter.
directionParameterDirectionThe 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
nameis null.- ArgumentException
nameis 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
namestringThe name of the parameter.
valuecharThe value of the parameter.
typeTDbTypeThe database type of the parameter.
directionParameterDirectionThe 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
nameis null.- ArgumentException
nameis 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
namestringThe name of the parameter.
valuestringThe value of the parameter.
typeTDbTypeThe database type of the parameter.
directionParameterDirectionThe 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
nameis null.- ArgumentException
nameis 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
namestringThe name of the parameter.
valueT?The value of the parameter.
typeTDbTypeThe database type of the parameter.
directionParameterDirectionThe direction of the parameter.
Returns
- TThis
This instance for use in method chaining.
Type Parameters
TThe 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
nameis null.- ArgumentException
nameis 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
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
nameis null.- ArgumentException
nameis 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
namestringThe name of the parameter.
typeTDbTypeThe database type of the parameter.
directionParameterDirectionThe 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
nameis null.- ArgumentException
nameis 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
namestringThe name of the parameter.
directionParameterDirectionThe 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
nameis null.- ArgumentException
nameis 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
valueTThe value of the parameter. A null is sent as a database null.
expressionstringThe text of the argument, supplied by the compiler. Do not pass it.
Returns
- TThis
This instance for use in method chaining.
Type Parameters
TThe 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
@namemarkers found in its SQL text (not those inside a string, a quoted identifier or a comment, and not@@systemvariables).
The argument is matched to one of them, trying in turn:
- exactly;
- ignoring case;
- ignoring case and underscores, so
AuthorIdfinds@author_id; -
failing those, for the same argument, after removing one common
parameter prefix from the real name
(
p_,in_,i_,prm_,par_,v_, or a lonepbefore a capital letter), soAuthorfinds@p_authorand@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.