This question is locked. New answers and comments are not allowed.
Hi,
I'm using the latest internal build with a custom aggregate function defined as belowed:
It works fine but sometimes, when i call CalculateAggregates, i get the following error:
System.ArgumentOutOfRangeException: Index was outsite the limit of the array
With the following stacktrace:
à System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
à System.ThrowHelper.ThrowArgumentOutOfRangeException()
à System.Collections.Generic.List`1.get_Item(Int32 index)
à System.Collections.ObjectModel.Collection`1.get_Item(Int32 index)
à lambda_method(ExecutionScope , DataRowContainer )
à System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
à System.Linq.Enumerable.Sum(IEnumerable`1 source)
à lambda_method(ExecutionScope , IGrouping`2 )
à System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
à Telerik.Windows.Data.QueryableExtensions.Aggregate(IQueryable source, IEnumerable`1 aggregateFunctions)
à Telerik.Windows.Controls.GridView.GridViewDataControl.CreateAggregateResults()
à Telerik.Windows.Controls.GridView.GridViewDataControl.CalculateAggregates()
Any ideas ?
Thanks !
I'm using the latest internal build with a custom aggregate function defined as belowed:
| public abstract class IndexedAggregateFunction : AggregateFunction |
| { |
| static MethodInfo s_genericSelect = typeof(Enumerable).GetMethods().Where(m => m.Name == "Select" && m.GetParameters()[1].ParameterType.GetGenericArguments().Length == 2).First(); |
| public override string FunctionName |
| { |
| get |
| { |
| return base.FunctionName; |
| } |
| set |
| { |
| base.FunctionName = value; |
| } |
| } |
| public override string ResultFormatString |
| { |
| get |
| { |
| return base.ResultFormatString; |
| } |
| set |
| { |
| base.ResultFormatString = value; |
| } |
| } |
| protected override string GenerateFunctionName() |
| { |
| return base.GenerateFunctionName(); |
| } |
| public int Index { get; set; } |
| protected abstract System.Linq.Expressions.Expression CreateAfterSelectionExpression(System.Linq.Expressions.Expression selectedEnumerableExpression); |
| protected System.Linq.Expressions.Expression GetDoubleSelectorExpression(System.Linq.Expressions.ParameterExpression param) |
| { |
| var propInfo = typeof(DataRowContainer).GetProperty("RawData"); |
| var methodInfo = typeof(ObservableCollection<object>).GetMethod("get_Item"); |
| return System.Linq.Expressions.Expression.Convert( |
| System.Linq.Expressions.Expression.Call( |
| System.Linq.Expressions.Expression.MakeMemberAccess(param, propInfo) |
| , methodInfo, System.Linq.Expressions.Expression.Constant(Index)), |
| typeof(double?)); |
| } |
| protected System.Linq.Expressions.Expression GetListOfDoubleExpression(System.Linq.Expressions.Expression param) |
| { |
| var methodInfo = s_genericSelect.MakeGenericMethod(typeof(DataRowContainer), typeof(double?)); |
| var selectorParam = System.Linq.Expressions.Expression.Parameter(typeof(DataRowContainer), "item"); |
| return System.Linq.Expressions.Expression.Call(methodInfo, param, System.Linq.Expressions.Expression.Lambda(GetDoubleSelectorExpression(selectorParam), selectorParam)); |
| } |
| protected System.Linq.Expressions.Expression GetAggregatedListOfDoubleExpression(System.Linq.Expressions.Expression param) |
| { |
| return CreateAfterSelectionExpression(GetListOfDoubleExpression(param)); |
| } |
| public override System.Linq.Expressions.Expression CreateAggregateExpression(System.Linq.Expressions.Expression enumerableExpression) |
| { |
| return GetAggregatedListOfDoubleExpression(enumerableExpression); |
| } |
| } |
| public class IndexedSumAggregateFunction : IndexedAggregateFunction |
| { |
| protected override System.Linq.Expressions.Expression CreateAfterSelectionExpression(System.Linq.Expressions.Expression selectedEnumerableExpression) |
| { |
| var method = typeof(Enumerable).GetMethod("Sum", new Type[] { typeof(IEnumerable<double?>) }); |
| return System.Linq.Expressions.Expression.Call(method, selectedEnumerableExpression); |
| } |
| } |
It works fine but sometimes, when i call CalculateAggregates, i get the following error:
System.ArgumentOutOfRangeException: Index was outsite the limit of the array
With the following stacktrace:
à System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
à System.ThrowHelper.ThrowArgumentOutOfRangeException()
à System.Collections.Generic.List`1.get_Item(Int32 index)
à System.Collections.ObjectModel.Collection`1.get_Item(Int32 index)
à lambda_method(ExecutionScope , DataRowContainer )
à System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
à System.Linq.Enumerable.Sum(IEnumerable`1 source)
à lambda_method(ExecutionScope , IGrouping`2 )
à System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
à Telerik.Windows.Data.QueryableExtensions.Aggregate(IQueryable source, IEnumerable`1 aggregateFunctions)
à Telerik.Windows.Controls.GridView.GridViewDataControl.CreateAggregateResults()
à Telerik.Windows.Controls.GridView.GridViewDataControl.CalculateAggregates()
Any ideas ?
Thanks !