IDataStore.GroupBy(string selectorKey, string sortKey = null) Method
.NET Standard 2.x
Groups rows of the primary buffer by the custom grouping criteria. The sort criteria can be specified.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public IEnumerable<IGrouping<object, IModelGetter>> GroupBy(string selectorKey, string sortKey = null);
Parameters
selectorkey
System.String
A comma-separated list of the columns or expressions that control the grouping of the data.
sortkey
System.String
A string whose value is the valid sort criteria for the DataStore. The expression includes column names or numbers. A column number must be preceded by a pound sign (#).
Default is null
which indicates it will use the current sort criteria in DataStore.
Returns
System.Collections.Generic.IEnumerable<IGrouping<System.Object, DWNet.Data.IModelGetter>>
Returns an IEnumerable<IGrouping<Object,IModelGetter>>
object which can be used to read data in groups.
Examples
The following code example groups the d_department_course DataStore by the studentgrade_studentid column.
using Appeon.ApiDoc.Models;
using DWNet.Data;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Appeon.ApiDoc.IDataStoreExamples
{
public class GroupByExample
{
private readonly SchoolContext _context;
public GroupByExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example5()
{
// Instantiates a DataStore object with datawindow: d_department_course.
var datastore = new DataStore("d_department_course", _context);
datastore.Retrieve();
// Sets the group by column and the sort by column.
var studentidGroup = datastore.GroupBy("studentgrade_studentid",
"studentgrade_studentid");
Console.WriteLine("Studentid Group Count: {0}", studentidGroup.Count());
/*This code produces the following output:
Studentid Group Count: 26
*/
}
}
}
Example Refer To
Model Class: D_Department_Course
DataWindow File: d_department_course
Applies to
.NET Standard
2.x