Show / Hide Table of Contents

    IDataStore.GroupBy<TModel>(Func<TModel, object> selectorKey) Method

    .NET Standard 2.x | Current Version (1.0.1)

    0.5.0-alpha

    1.0.1 (current)

    Generic method. Groups rows of the primary buffer by the custom grouping criteria defined by Func<TModel, object>.

    Namespace: PowerBuilder.Data

    Assembly: PowerBuilder.Data.dll

    Syntax

      public IEnumerable<IGrouping<object, TModel>> GroupBy<TModel>(Func<TModel, object> selector)
    

    Type Parameters

    TModel

    The type of a model class that matches with the current DataObject.

    Parameters

    selectorkey System.Func<System.Object, TModel>

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

    Returns

    System.Collections.Generic.IEnumerable<IGrouping<System.Object, TModel>>

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

    Examples

    The following code example groups the d_department_course DataStore by the course_departmentid column.

    using PowerBuilder.Data;
    using System;
    using System.Linq;
    
    namespace Appeon.ApiDoc.IDataStoreExamples
    {
        public class GroupByExample
        {
            private SchoolContext _context;
    
            public GroupByExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example7()
            {
                // Instantiates a DataStore object with datawindow: d_department_course.
                var datastore = new DataStore("d_department_course", _context);
    
                datastore.Retrieve();
    
                // Sets the group by column to course_departmentid via a delegate.
                // This function provides no sort capabilities.
                var departmentGroup = datastore.GroupBy<D_Department_Course>(
                    d => d.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

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon