DwComputeAttribute Class
.NET Standard 2.x
Specifies the computed column.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Inheritance Constructor
System.Attribute
Syntax
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class DwComputeAttribute : PropertySaveAttribute
Constructors
Name | Description |
---|---|
DwComputeAttribute(string expression) | Initializes a new instance of the DwComputeAttribute class. |
Properties
Name | Return Type | Description |
---|---|---|
Expression | string | Computed column expression. |
Remarks
Corresponding to the computed column defined by DataWindow.
Examples
The following code example demonstrates how to use the Model DwCompute attribute to define a computed column, and get the value of this computed column.
Model: D_Person_With_Dwcompute
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_dwcompute", DwStyle.Grid)]
[Table("Person")]
#region DwSelectAttribute
[DwSelect("PBSELECT( VERSION(400) TABLE(NAME=\"Person\" ) @(_COLUMNS_PLACEHOLDER_) )")]
#endregion
[DwKeyModificationStrategy(UpdateSqlStrategy.DeleteThenInsert)]
[UpdateWhereStrategy(UpdateWhereStrategy.KeyAndConcurrencyCheckColumns)]
public class D_Person_With_Dwcompute
{
[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; }
[JsonIgnore]
[DwCompute("firstname + \" \" + lastname")]
public object Compute_Fullname { get; set; }
}
}
Example Method:
using System;
using DWNet.Data;
namespace Appeon.ApiDoc.DwComputeAttributeExamples
{
public class DwComputeAttributeExample
{
private readonly SchoolContext _context;
public DwComputeAttributeExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example()
{
var datastore = new DataStore("d_person_with_dwcompute", _context);
datastore.Retrieve();
//Gets the full name by the computed column in the first row.
string fullName = datastore.GetItem<string>(0, "Compute_Fullname");
// Shows the value of the computed column.
Console.WriteLine($"fullName={fullName}.");
/* This code example produces the following output:
fullName=Kim Abercrombie.
*/
}
}
}
Example Refer To
DataWindow File: D_Person_With_Dwcompute