Show / Hide Table of Contents

    IDataStore<TModel>.GroupBy<TKey>(Func<TModel, TKey> keySelector) Method

    .NET Standard 2.x

    Groups rows of the primary buffer by the level of grouping criteria of DataStore. The sort criteria can be specified.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

    IEnumerable<IGrouping<TKey, TModel>> GroupBy<TKey>(Func<TModel, TKey> keySelector);
    

    Type Parameters

    TKey

    Parameters

    keySelector Func<TModel, TKey>

    A Func<Object, TModel> used to define the grouping criteria.

    Returns

    IEnumerable<IGrouping<TKey, TModel>>

    Returns an IEnumerable<IGrouping<TKey,TModel>> object which can be used to read data in groups.

    Examples

    The 'd_department_course' contains two levels of groups: the primary group is grouped by course_departmentid; the nested group is grouped by course_courseid. The following code example demonstrates how to get the primary group and return the data of this group.

    using Appeon.ApiDoc.Models;
    using DWNet.Data;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    
    namespace Appeon.ApiDoc.IDataStore_GenericExamples
    {
        public class GroupByExample
        {
            private readonly SchoolContext _context;
    
            public GroupByExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example1()
            {
                // Instantiates a DataStore object with datawindow: d_department_course.
                var datastore = new DataStore<D_Department_Course>(_context);
    
                datastore.Retrieve();
    
                // The primary group is by course_departmentid which has only 4 values.
                var departmentGroup = datastore.GroupBy(a => a.Course_Departmentid);
    
                Console.WriteLine("Department Group Count: {0}", departmentGroup.Count());
    
                /*This code produces the following output:
                 
                Department Group Count: 4
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department_Course
    DataWindow File: d_department_course

    Back to top Generated by Appeon