DwParameterAttribute Class
.NET Standard 2.x
Specifies the parameters required by the query statement.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Inheritance Constructor
System.Attribute
Syntax
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class DwParameterAttribute : SqlParameterAttribute
Constructors
Name | Description |
---|---|
DwParameterAttribute(string name, Type dataType) | Initializes a new instance of the DwParameterAttribute class. |
Properties
Name | Return Type | Description |
---|---|---|
Name | string | The name of the parameter. |
DataType | Type | The data type of the parameter. |
Remarks
Corresponding to the parameters defined by the DataWindow.
The parameter can be referenced by its name in the select syntax for the other attributes in the model class. The format to make reference: :paramName
.
Examples
The following code example demonstrates how to use the Model DwParameter attribute. If the DwParameter attribute is defined in the Model, which means the parameter will be used by the SQL statement, then the parameter must be passed in when retrieving data.
Model: D_Person_With_Parameter
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using SnapObjects.Data;
using DWNet.Data;
using Newtonsoft.Json;
using System.Collections;
namespace Appeon.ApiDoc.Models
{
[DataWindow("d_person_with_parameter", DwStyle.Grid)]
[Table("Person")]
#region DwSelectAttribute
[DwSelect("PBSELECT( VERSION(400) TABLE(NAME=\"Person\" ) @(_COLUMNS_PLACEHOLDER_) WHERE( EXP1 =\"Person.Discriminator\" OP =\"=\" EXP2 =\":s_Discriminator\" ) ) ARG(NAME = \"s_Discriminator\" TYPE = string)")]
#endregion
[DwParameter("s_Discriminator", typeof(string))]
[DwKeyModificationStrategy(UpdateSqlStrategy.DeleteThenInsert)]
[UpdateWhereStrategy(UpdateWhereStrategy.KeyAndConcurrencyCheckColumns)]
public class D_Person_With_Parameter
{
[Key]
[Identity]
[DwColumn("Person", "PersonID")]
public int Personid { get; set; }
[ConcurrencyCheck]
[StringLength(50)]
[DwColumn("Person", "LastName")]
public string Lastname { get; set; }
[ConcurrencyCheck]
[StringLength(50)]
[DwColumn("Person", "FirstName")]
public string Firstname { get; set; }
[ConcurrencyCheck]
[DwColumn("Person", "HireDate")]
public DateTime? Hiredate { get; set; }
[ConcurrencyCheck]
[DwColumn("Person", "EnrollmentDate")]
public DateTime? Enrollmentdate { get; set; }
[ConcurrencyCheck]
[StringLength(50)]
[DwColumn("Person", "Discriminator")]
public string Discriminator { get; set; }
}
}
Example Method:
using System;
using DWNet.Data;
namespace Appeon.ApiDoc.DwParameterAttributeExamples
{
public class DwParameterAttributeExample
{
private readonly SchoolContext _context;
public DwParameterAttributeExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example()
{
var datastore = new DataStore("d_person_with_parameter", _context);
datastore.Retrieve("Student");
/* The following Select SQL is generated:
exec sp_executesql N'SELECT
[Person].[PersonID],
[Person].[LastName],
[Person].[FirstName],
[Person].[HireDate],
[Person].[EnrollmentDate],
[Person].[Discriminator]
FROM [Person]
WHERE ([Person].[Discriminator] = @s_Discriminator)',N'@s_Discriminator nvarchar(4000)',@s_Discriminator=N'Student'
*/
}
}
}
Example Refer To
DataWindow File: d_person_with_parameter