DwSortAttribute Class
.NET Standard 2.x
Specifies the sort criteria.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Inheritance Constructor
System.Attribute
Syntax
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class DwSortAttribute : Attribute
Constructors
Name | Description |
---|---|
DwSortAttribute(string expression) | Initializes a new instance of the DwSortAttribute class. |
Properties
Name | Return Type | Description |
---|---|---|
Expression | string | The sort criteria. |
Remarks
Corresponding to the sort criteria defined by DataWindow.
Examples
The following code example demonstrates how to use the Model DwSort attribute.If the DwSort attribute is defined in the DataStore, the sort criteria is automatically applied after data is retrieved.The example sorts data by personid in the descending order.
Model: D_Person_With_Sort
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_sort", DwStyle.Grid)]
[Table("Person")]
#region DwSelectAttribute
[DwSelect("PBSELECT( VERSION(400) TABLE(NAME=\"Person\" ) @(_COLUMNS_PLACEHOLDER_) )")]
#endregion
[DwSort("personid D")]
[DwKeyModificationStrategy(UpdateSqlStrategy.DeleteThenInsert)]
[UpdateWhereStrategy(UpdateWhereStrategy.KeyAndConcurrencyCheckColumns)]
public class D_Person_With_Sort
{
[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.DwSortAttributeExamples
{
public class DwSortAttributeExample
{
private readonly SchoolContext _context;
public DwSortAttributeExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example()
{
var datastore = new DataStore("D_Person_With_Sort", _context);
datastore.Retrieve();
int Personid = datastore.GetItem<int>(0, "Personid");
// Shows the value of Personid of the first row in DataStore.
Console.WriteLine($"The value of Personid of the first row in datastore is Personid={Personid}.");
/* This code example produces the following output:
The value of Personid of the first row in datastore is Personid=34.
*/
}
}
}
Example Refer To
DataWindow File: d_person_with_sort