Method AddParams
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Core.dll
AddParams<T>(T)
Adds the public properties and fields of source as parameters, under the real names the stored procedure declares for them (AuthorId as @author_id).
public TThis AddParams<T>(T source) where T : notnull
Parameters
sourceTThe object to read the values from.
Returns
- TThis
This instance for use in method chaining.
Type Parameters
TThe type of the object whose members are the parameters.
Remarks
Each member is matched to the stored procedure's real parameter names the same way as AddParam<T>(T, string?).
When the real names are known, a member that the procedure does not declare is not sent (the names are read again once first, in case the procedure gained it), so one object can serve several procedures; parameters the procedure declares that no member matches are left to default values or to explicit AddParam calls.
Where the real names are not known (a text command with no @name marker, or a provider that does not supply them) every member is sent under its own name.
A parameter you add with AddParam, by name or from an argument, wins over a member that resolves to the same name.
Every public readable property and field is read when this method is called, whether or not the procedure declares it, so a getter that throws or loads lazily runs then. Static members and indexers are ignored.
The members are those of the static type T, not of the object's runtime type: an interface adds only its own. The one exception is object: a variable typed object, or the result of a Func<T, object>, has no members of its own, so the members of its runtime type are used.
Nested objects are not flattened (pass post.Author itself).
Exceptions
- ArgumentNullException
sourceis null.
AddParams(TCommand)
Handles adding the list of parameters to a new command.
protected abstract void AddParams(TCommand command)
Parameters
commandTCommandThe command to add parameters to.