IDataStore.GroupBy<TModel>(Func<TModel, object> selectorKey, bool isneighbor) Method
.NET Standard 2.x
Generic method. Groups rows of the primary buffer by the custom grouping criteria defined by Func<TModel, object>
.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
IEnumerable<IGrouping<object, TModel>> GroupBy<TModel>(Func<TModel, object> selectorKey, bool isneighbor);
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.
isneighbor
System.Boolean
Whether to consider adjacent elements.
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 DataStore by the course_courseid column and whether to consider adjacent elements.
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 Example8()
{
// Instantiates a DataStore object with datawindow: d_department_course.
var datastore = new DataStore("d_department_course", _context);
// Creates a list of D_Department_Course objects.
var departments = new List<D_Department_Course>
{
new D_Department_Course{ Course_Courseid = 1 },
new D_Department_Course{ Course_Courseid = 2 },
new D_Department_Course{ Course_Courseid = 1 }
};
// Appends the list of objects as rows to the end of the primary buffer in the DataStore.
datastore.AddRow(departments);
// 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_Courseid, false);
// course_courseid is the same and is adjacent to each other.
var departmentGroup2 = datastore.GroupBy<D_Department_Course>(
d => d.Course_Courseid, true);
Console.WriteLine("Department Group Count:{0}", departmentGroup.Count());
Console.WriteLine("Department Group Count:{0}", departmentGroup2.Count());
/*This code produces the following output:
Department Group Count: 2
Department Group Count: 3
*/
}
}
}
Example Refer To
Model Class: D_Department_Course
DataWindow File: d_department_course
Applies to
.NET Standard
2.x