DwFilterAttribute Class
.NET Standard 2.x
Specifies the filter criteria for the model.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Inheritance Constructor
System.Attribute
Syntax
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class DwFilterAttribute : Attribute
Constructors
Name | Description |
---|---|
DwFilterAttribute(string expression) | Initializes a new instance of the DwFilterAttribute class. |
Properties
Name | Return Type | Description |
---|---|---|
Expression | string | Filter expression |
Remarks
A model can have filter criteria specified as part of its definition. When data is retrieved, only rows meeting the criteria will be loaded to the model.
The filter expression consists of columns, relational operators, and values against which column values are compared. Boolean expressions can be connected with logical operators AND and OR.
Examples
The following code example demonstrates how to use the Model DwFilter attribute.If the DwFilter attribute is defined in the DataStore, the filter criteria in DwFilter is automatically applied after the data is retrieved, and the data that do not meet the criteria is moved to the filter buffer.
Model: D_Person_With_Filter
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_filter", DwStyle.Grid)]
[Table("Person")]
#region DwSelectAttribute
[DwSelect("PBSELECT( VERSION(400) TABLE(NAME=\"Person\" ) @(_COLUMNS_PLACEHOLDER_) )")]
#endregion
[DwFilter(" discriminator = 'Student'")]
[DwKeyModificationStrategy(UpdateSqlStrategy.DeleteThenInsert)]
[UpdateWhereStrategy(UpdateWhereStrategy.KeyAndConcurrencyCheckColumns)]
public class D_Person_With_Filter
{
[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.DwFilterAttributeExamples
{
public class DwFilterAttributeExample
{
private readonly SchoolContext _context;
public DwFilterAttributeExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example()
{
var datastore = new DataStore("d_person_with_filter", _context);
datastore.Retrieve();
// Shows the total number of rows in the filter buffer
Console.WriteLine($"datastore FilteredCount={datastore.FilteredCount}.");
/* This code example produces the following output:
datastore FilteredCount=9.
*/
}
}
}
Example Refer To
DataWindow File: d_person_with_filter