ParamValue.New<Type>(string name, object value, ParameterDirection direction = ParameterDirection.Input) Method
.NET Standard 2.x
Creates a new ParamValue
object and specifies the name and value of the parameter.
You can also specify the direction type of the parameter. The default is ParameterDirection.Input
.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public static ParamValue New<Type>(string name, object value, ParameterDirection direction = ParameterDirection.Input)
Type Parameters
Type
The datatype of the parameter value.
Parameters
name
System.String
The name of the parameter.
value
System.Object
The value of the parameter.
direction
System.Data.ParameterDirection
(Optional) The direction type of the parameter.
The default is ParameterDirection.Input
.
Returns
Returns the newly created ParamValue
object.
Examples
The following code example creates a ParamValue
object and specifies its name, value, and direction. then uses it together with SqlExecutor
.
using Appeon.ApiDoc.Models.School;
using SnapObjects.Data;
using System;
using System.Data;
namespace Appeon.ApiDoc.ParamValueExamples
{
public class NewExample
{
private readonly SchoolContext _context;
public NewExample(SchoolContext context)
{
_context = context;
}
public void Example2()
{
// Creates a ParamValue object with a string type
// and the input direction.
var paramValue = ParamValue.New<string>("nameArgument",
"Economics",
ParameterDirection.Input);
// Gets and shows the name, value and direction of the ParamValue object.
Console.WriteLine("ParamValue.Name = {0}", paramValue.Name);
Console.WriteLine("ParamValue.Value = {0}", paramValue.Value);
Console.WriteLine("ParamValue.DataType = {0}", paramValue.DataType);
Console.WriteLine("ParamValue.Direction = {0}", paramValue.Direction);
// Gets a SqlModelMapper object.
var mapper = _context.SqlModelMapper;
// Passes it the ParamValue object when querying data.
var dept = mapper.Load<DepartmentByName>(paramValue).FirstOrDefault();
/*This code produces the following output:
ParamValue.Name = data1
ParamValue.Value = Economics
ParamValue.DataType = System.String
ParamValue.Direction = Input
*/
}
}
}
Example Refer To
Model Class: DepartmentByName
Applies to
.NET Standard
2.x