Show / Hide Table of Contents

    DwSelectAttribute Class

    .NET Standard 2.x

    Specifies the query statement.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Inheritance Constructor

    System.Attribute

    Syntax

        [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
        public class DwSelectAttribute : Attribute
    

    Constructors

    Name Description
    DwSelectAttribute(string select) Initializes a new instance of the DwSelectAttribute class.

    Properties

    Name Return Type Description
    Select string The query statement.

    Remarks

    Corresponding to the DataWindow query statement.

    If the query statement is a PBSelect, use @(_COLUMNS_PLACEHOLDER_) to replace the column definition, for easier maintenance of columns.

    Examples

    The following code example demonstrates how to use the Model DwSelect attribute. The DwSelect attribute uses the PBSELECT syntax which will be used to generate standard SQL statement when retrieving data.

    Model: D_Person
    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_person", DwStyle.Grid)]
        [Table("Person", Schema = "dbo")]
        #region DwSelectAttribute  
        [DwSelect("PBSELECT( VERSION(400) TABLE(NAME=\"Person\" ) @(_COLUMNS_PLACEHOLDER_) )")]
        #endregion
        [UpdateWhereStrategy(UpdateWhereStrategy.KeyAndConcurrencyCheckColumns)]
        [DwKeyModificationStrategy(UpdateSqlStrategy.DeleteThenInsert)]
        public class D_Person
        {
            [Key]
            [Identity]
            [DwColumn("Person", "PersonID")]
            public int Personid { get; set; }
    
            [ConcurrencyCheck]
            [DwColumn("Person", "LastName")]
            public string Lastname { get; set; }
    
            [ConcurrencyCheck]
            [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]
            [DwColumn("Person", "Discriminator")]
            public string Discriminator { get; set; }
    
        }
    
    }
    
    Example Method:
    using System;
    using DWNet.Data;
    
    namespace Appeon.ApiDoc.DwSelectAttributeExamples
    {
        public class DwSelectAttributeExample
        {
            private readonly SchoolContext _context;
    
            public DwSelectAttributeExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example()
            {
                var datastore = new DataStore("d_person", _context);
                datastore.Retrieve();
    
                /* The following SQL is generated:
                
                SELECT
                 [Person].[PersonID],
                [Person].[LastName],
                [Person].[FirstName],
                [Person].[HireDate],
                [Person].[EnrollmentDate],
                [Person].[Discriminator] 
                FROM [Person]
                */
            }
        }
    }
    

    Example Refer To

    DataWindow File: d_person

    Back to top Generated by Appeon