Show / Hide Table of Contents

    DwGroupByAttribute Class

    .NET Standard 2.x

    Specifies the grouping criteria, corresponding to the grouping defined by DataWindow.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Inheritance Constructor

    System.Attribute

    Syntax

        [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
        public class DwGroupByAttribute : Attribute
    

    Constructors

    Name Description
    DwGroupByAttribute(short level, params string[] groupBy) Initializes a new instance of the DwGroupByAttribute class.

    Properties

    Name Return Type Description
    Level short Level of groups.
    GroupBy string[] The grouping criteria.
    SortBy string The sorting criteria for groups.

    Remarks

    You can group and sort data. Data can be divided into different groups by using the Level property. The GroupBy expression may consist of one or more model attributes, separated by comma (","). The SortBy expression specifies the sorting criteria for each group.

    Examples

    The following code example demonstrates how to use the Model DwGroupBy attribute. If the DwGroupBy attribute is defined in DataStore, you can use GroupBy to get the information of groups.

    Model: D_Person_With_Group
    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_group", DwStyle.Grid)]
        [Table("Person")]
        #region DwSelectAttribute  
        [DwSelect("PBSELECT( VERSION(400) TABLE(NAME=\"Person\" ) @(_COLUMNS_PLACEHOLDER_) )")]
        #endregion
        [DwSort("discriminator A")]
        [DwGroupBy(1, "discriminator")]
        [DwKeyModificationStrategy(UpdateSqlStrategy.DeleteThenInsert)]
        [UpdateWhereStrategy(UpdateWhereStrategy.KeyAndConcurrencyCheckColumns)]
        public class D_Person_With_Group
        {
            [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 System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using DWNet.Data;
    
    namespace Appeon.ApiDoc.DwGroupByAttributeExamples
    {
        public class DwGroupByAttributeExample
        {
            private readonly SchoolContext _context;
    
            public DwGroupByAttributeExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example()
            {
                var datastore = new DataStore("d_person_with_group", _context);
                datastore.Retrieve();
    			
    			//Gets the results that meet the grouping criterion.
                var groups = datastore.GroupBy();
    
                // Shows the total number of groups.
                Console.WriteLine($"datastore has {groups.Count()} groups.");
    
                /* This code example produces the following output:
                
                datastore has 2 groups.
                */
            }
        }
    }
    

    Example Refer To

    DataWindow File: d_person_with_group

    Back to top Generated by Appeon