New to Telerik UI for WPF? Download free 30-day trial

Exception with Sum AggregateFuntion

PROBLEM

You declare an aggregate SumFunction for a column:

<telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"> 
    <telerik:GridViewDataColumn.AggregateFunctions> 
        <telerik:SumFunction/> 
    </telerik:GridViewDataColumn.AggregateFunctions> 
</telerik:GridViewDataColumn> 
As a result, the following error occurs: No generic method 'Sum' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.

CAUSE

You can sum only Numeric types.

SOLUTION

You can create a Generic AggregateFunction instead and return the Sum of the values.

You can also specify some custom aggregate expressions. Then add the defined function to the AggregateFunctions collection of GridViewDataColumn as illustrated in this help topic.

For example you can define a generic AggregateFunction which calculates the Sum of the Numbers for all the Players populated in RadGridView. You can refer to the sample code below:

var aggregate = new AggregateFunction<Player, int>() 
{ 
    AggregationExpression = players => players.Select(x => x.Number).Sum() 
}; 
playersGrid.Columns[0].AggregateFunctions.Add(aggregate); 

See Also

In this article