IDataStore.GroupBy<TModel>(Func<TModel, object> selectorKey) 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
public IEnumerable<IGrouping<object, TModel>> GroupBy<TModel>(Func<TModel, object> selectorKey)
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 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 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
DataWindow File: d_department_course
Applies to
.NET Standard
2.x