cmd.AddTableRowParam - lobodava/artisan-orm GitHub Wiki
cmd.AddTableRowParam(name, value) adds a one-row table-valued parameter. For entity types it uses the registered mapper's CreateDataTable and CreateDataRow methods; it does not execute the command.
The following method belongs to a RepositoryBase subclass. It assumes dbo.SaveUsers accepts @User as a READONLY parameter of the mapper's SQL table type:
public int SaveUser(User user)
{
return ExecuteCommand(cmd =>
{
cmd.UseProcedure("dbo.SaveUsers");
cmd.AddTableRowParam("@User", user);
});
}The returned integer is the procedure's T-SQL RETURN value. To return the saved entity instead, the procedure must SELECT that entity, and the repository must execute a corresponding read (for example through GetByCommand and cmd.ReadTo<User>()). ExecuteCommand does not return a User.
The overload AddTableRowParam(name, value, tableName, columnNames) auto-maps one entity using the explicit property list. Its generic entity type must not implement IEnumerable. Dedicated overloads accept a single byte, short, int, or long ID.
See table parameters for mapping and schema requirements, and parameter implementation for the overloads.