Show / Hide Table of Contents

    DwColumnAttribute Class

    .NET Standard 2.x

    Specifies the column data information.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Inheritance Constructor

    System.Attribute

    Syntax

        [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
        public class DwColumnAttribute : SqlColumnAttribute
    

    Constructors

    Name Description
    DwColumnAttribute(string column) Initializes a new instance of the DwColumnAttribute class.
    DwColumnAttribute(string tableAlias, string column) Initializes a new instance of the DwColumnAttribute class.
    DwColumnAttribute(string tableAlias, string column, string columnAlias) Initializes a new instance of the DwColumnAttribute class.

    Properties

    Name Return Type Description
    Column string Gets the name of the column the property is mapped to.
    ColumnAlias string Gets the alias of the column the property is mapped to.
    Order int Gets or sets the zero-based order of the column the property is mapped to.
    TableAlias string Gets the alias of the table where the column belongs to.
    TypeName string Gets or sets the data type of the column the property is mapped to.
    Validation string Gets or sets the validation rule for the column.
    ValidationMsg string Gets or sets the validation message.

    Remarks

    Corresponding to the column defined by DataWindow.

    DwColumnAttribute has a few overriding constructors which allow table alias and column alias to be passed in.

    Examples

    The following code example enables the column placeholder @(COLUMNS_PLACEHOLDER) in the DwSelect attribute of Model, which means the SQL statement to be generated when data is retrieved will use the column name placeholder @(COLUMN_PLACEHOLDER) to replace all column names in DwSelect.

    Model: D_Department
    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;
    
    namespace Appeon.ApiDoc.Models
    {
        [DataWindow("d_department", DwStyle.Grid)]
        [Table("Department", Schema = "dbo")]
        #region DwSelectAttribute  
        [DwSelect("PBSELECT( VERSION(400) TABLE(NAME=\"Department\" ) @(_COLUMNS_PLACEHOLDER_) )")]
        #endregion
        [UpdateWhereStrategy(UpdateWhereStrategy.KeyAndConcurrencyCheckColumns)]
        [DwKeyModificationStrategy(UpdateSqlStrategy.DeleteThenInsert)]
        [DwTemplate(DataFormat.Xml, "xml_default", "Templates\\xml_setparameter_default.xml", IsDefault = true)]
        public class D_Department
        {
            [Key]
            [DwColumn("Department", "DepartmentID")]
            public int Departmentid { get; set; }
    
            [ConcurrencyCheck]
            [DwColumn("Department", "Name")]
            public string Name { get; set; }
    
            [ConcurrencyCheck]
            [DwColumn("Department", "Budget")]
            public decimal Budget { get; set; }
    
            [ConcurrencyCheck]
            [DwColumn("Department", "StartDate")]
            public DateTime Startdate { get; set; }
    
            [ConcurrencyCheck]
            [DwColumn("Department", "Administrator")]
            public int? Administrator { get; set; }
    
        }
    
    }
    
    Example Method:
    using System;
    using DWNet.Data;
    
    namespace Appeon.ApiDoc.DwColumnAttributeExamples
    {
        public class DwColumnAttributeExample
        {
            private readonly SchoolContext _context;
    
            public DwColumnAttributeExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example()
            {
                // Instantiates a DataStore object with datawindow: d_department.
                var datastore = new DataStore("d_department", _context);
    
                // Retrieves rows from the database for datastore
                datastore.Retrieve();
    
                /*The following SQL is generated:
                
                SELECT
                [Department].[DepartmentID],
                [Department].[Name],
                [Department].[Budget],
                [Department].[StartDate],
                [Department].[Administrator] 
                FROM [Department]
                */
            }
        }
    }
    

    Example Refer To

    DataWindow File: d_department

    Back to top Generated by Appeon