Grouping and Aggregating Data
The OpenAccessLinqDataSource control enables you to group data by one or more columns. You use the grouping option to specify which properties are used for consolidating data records that have the same values. For example, if you configure OpenAccessLinqDataSource to group the rows from the Car table (SofiaCarRental) by the Make column, all the records in the returned result that have the same Make property value are returned as a single consolidated record. The GroupBy statement is used in conjunction with the aggregate functions to group the result set by one or more columns. This topic illustrates how to use the OpenAccessLinqDataSource control to group and aggregate data.
You cannot insert, update or delete records when you are working with grouped data.
Grouping and Aggregating Data
To create a new GroupBy expression, you need to specify values for the GroupBy, OrderGroupsBy, and Select properties of OpenAccessLinqDataSource. GroupBy holds the column you want to use to group the data, OrderGroupsBy specifies the order of the groups (key equals ascending, and "key desc" equals descending), and Select contains the aggregation expression.
OpenAccessLinqDataSource supports the following aggregation methods: Average, Min, Max, and Sum.
<telerik:OpenAccessLinqDataSource
ID="OpenAccessLinqDataSourceCar" runat="server"
ContextTypeName="SofiaCarRental.Model.FluentModel" ResourceSetName="Cars"
GroupBy="Make" OrderGroupsBy="key"
Select="new (key as Make, it as Cars, Average(Rating) as Average_Rating)">
</telerik:OpenAccessLinqDataSource>