Show / Hide Table of Contents

    IGroupingGetter<TModel> Interface

    .NET Standard 2.x

    Represents the getter for a group, where each row of data in the last level of the group corresponds to a TModel object. Used in conjunction with the grouping function of the DataStore.

    When the IsGroup property is true, it is used to get a group of data; when the IsGroup property is false, you can access the Value property to get the data of a certain row.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

    public interface IGroupingGetter<TModel>;
    

    Properties

    Name Return Type Description
    IsGroup int Whether the current IGroupingGetter object represents a group.
    Key object When the IsGroup property is true, represents the common key of the objects in the current group.
    Value object When IsGroup is false, gets a row of data.

    Method

    Name Return Type Description
    GetEnumerator() IEnumerator<IGroupingGetter<TModel>> When the IsGroup property is true, returns an enumerator that iterates through the group.

    Examples

    The following code example creates an instance of GroupingGetter and receives data in a model object.

    using Appeon.ApiDoc.Models;
    using DWNet.Data;
    using System;
    
    namespace Appeon.ApiDoc.IGroupingGetter_GenericExamples
    {
        public class IGroupingGetter_GenericExample
        {
            private readonly SchoolContext _context;
    
            public IGroupingGetter_GenericExample(SchoolContext context)
            {
                _context = context;
            }
    
            public void Example()
            {
                // Creates a datastore object
                IDataStore course = new DataStore("d_department_course", _context);
    
                course.Retrieve();
    
                var departmentGropup = course.GroupBy<D_Department_Course>();
    
                // Gets the grouped data of the first level
                foreach (var m in departmentGropup)
                {
                    Console.WriteLine("Level1 Group key = {0}", m.Key);
    
                    // Gets the grouped data of the second level
                    foreach (var getter in m)
                    {
                        Console.WriteLine(" Level2 Group key = {0}", getter.Key);
    
                        // Shows the Course_Title value in each group in a loop
                        foreach (var model in getter)
                        {                        
                            Console.WriteLine("  Course_Title = {0}", model.Value.Course_Title);
                        }
                       
                    }
                }
    
                /*This code produces the following output:
                
                Level1 Group key = 1
                 Level2 Group key = 1050
                  Course_Title = Chemistry
                  Course_Title = Chemistry
                  Course_Title = Chemistry
                 Level2 Group key = 1061
                  Course_Title = Physics
                  Course_Title = Physics
                  Course_Title = Physics
                  Course_Title = Physics
                  Course_Title = Physics
                  Course_Title = Physics
                  Course_Title = Physics
                Level1 Group key = 2
                 Level2 Group key = 2021
                  Course_Title = Composition
                  Course_Title = Composition
                  Course_Title = Composition
                  Course_Title = Composition
                  Course_Title = Composition
                 Level2 Group key = 2030
                  Course_Title = Poetry
                  Course_Title = Poetry
                 Level2 Group key = 2042
                  Course_Title = Literature
                  Course_Title = Literature
                  Course_Title = Literature
                
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department_Course
    DataWindow File: d_department_course

    Back to top Generated by Appeon