This is a migrated thread and some comments may be shown as answers.

Error when binding to Aggregate SumFunction

12 Answers 336 Views
GridView
This is a migrated thread and some comments may be shown as answers.
tungnt185
Top achievements
Rank 2
tungnt185 asked on 02 Dec 2009, 11:55 AM
Hello Telerik team,
I've error when I'm using Aggregate function in Column Grid.
 
<telerikGridView:GridViewDataColumn HeaderTextAlignment="Center" TextAlignment="Right" DataMemberBinding="{Binding EmployeeDeduction}"
                        <telerikGridView:GridViewDataColumn.AggregateFunctions> 
                            <telerikData:SumFunction FunctionName="EmployeeDeduction" SourceField="EmployeeDeduction" ResultFormatString="{}{0:c}" /> 
                        </telerikGridView:GridViewDataColumn.AggregateFunctions> 
</telerikGridView:GridViewDataColumn> 

The error message like below in stack trace. When I use Count Function everything work fine but when I use Sum,Min,Max function error occurs. My EmployeeDeduction has data type is Money in SQL server 2008. I think it's a bug of Aggregate Sum function in Q3.

Message: Unhandled Error in Silverlight Application 
Code: 4004     
Category: ManagedRuntimeError        
Message: System.ArgumentException: Invalid property or field - 'EmployeeDeduction' for type: Entity 
   at Telerik.Windows.Data.Expressions.MemberAccessTokenExtensions.CreateMemberAccessExpression(IMemberAccessToken token, Expression instance) 
   at Telerik.Windows.Data.Expressions.ExpressionFactory.MakeMemberAccess(Expression instance, String memberName) 
   at Telerik.Windows.Data.Expressions.ExpressionFactory.MakeMemberAccess(Expression instance, String memberName, Boolean liftMemberAccessToNull) 
   at Telerik.Windows.Data.Expressions.PropertyAccessExpressionBuilder.CreateMemberAccessExpression() 
   at Telerik.Windows.Data.Expressions.EnumerableSelectorAggregateFunctionExpressionBuilder.CreateMemberSelectorExpression() 
   at Telerik.Windows.Data.Expressions.EnumerableSelectorAggregateFunctionExpressionBuilder.CreateAggregateExpression() 
   at Telerik.Windows.Data.EnumerableSelectorAggregateFunction.CreateAggregateExpression(Expression enumerableExpression) 
   at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilder.<ProjectionPropertyValueExpressions>b__3(AggregateFunction f) 
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() 
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) 
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) 
   at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilder.CreateProjectionInitExpression() 
   at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilder.CreateAggregateFunctionsProjectionMemberBinding() 
   at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilder.<CreateMemberBindings>d__0.MoveNext() 
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source) 
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) 
   at System.Linq.Expressions.ReadOnlyCollectionExtensions.ToReadOnlyCollection[T](IEnumerable`1 sequence) 
   at System.Linq.Expressions.Expression.MemberInit(NewExpression newExpression, IEnumerable`1 bindings) 
   at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilder.CreateSelectBodyExpression() 
   at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilder.CreateSelectExpression() 
   at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilderBase.CreateQuery() 
   at Telerik.Windows.Data.QueryableExtensions.Aggregate(IQueryable source, IEnumerable`1 aggregateFunctions) 
   at Telerik.Windows.Controls.GridView.GridViewDataControl.CreateAggregateResults() 
   at Telerik.Windows.Controls.GridView.GridViewDataControl.CalculateAggregates() 
   at Telerik.Windows.Controls.GridView.GridViewDataControl.<>c__DisplayClass37.<Bind>b__36() 
   at Telerik.Windows.Controls.CursorManager.PerformTimeConsumingOperation(FrameworkElement frameworkElement, Action action) 
   at Telerik.Windows.Controls.GridView.GridViewDataControl.Bind(Object newValue) 
   at Telerik.Windows.Controls.GridView.GridViewDataControl.OnApplyTemplate() 
   at System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget)      
 
Line: 57 
Char: 13 
Code: 0 

12 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 02 Dec 2009, 12:42 PM
Hi,

This exception is related to not finding property in the resolved item type - can you sort, group or filter by this field in your case? Please post also more info about how the grid is bound.

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
tungnt185
Top achievements
Rank 2
answered on 03 Dec 2009, 01:43 AM
Hello,
Everything worked fine when I comment out AggregateFunction portion.
I'm using WCF RIA service PDC to for Model then I'm used a ViewModel to bind to DataContext in the View.
After I used DomainDataSource.Data in ViewModel for binding to RadGridView's ItemsSource.
Beside I also bind SelectedItem and CurrentItem of this RadGridView to DomainDataSource.DataView.CurrentItem with Mode = TwoWay.
I don't know if this help you find out my problems ?
0
Vlad
Telerik team
answered on 03 Dec 2009, 07:12 AM
Hi,

It will be better if you can send us small example (via support ticket) where we can reproduce and debug the grid behavior in your scenario.

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
tungnt185
Top achievements
Rank 2
answered on 07 Dec 2009, 08:26 AM
Hello again,

I've send you an support ticket with an example.
Please test it and give me a solution.

Thanks you very much.
0
Saumil Shah
Top achievements
Rank 1
answered on 23 Feb 2010, 01:37 PM
I am getting the same error. Please let me know if anyone of you found the solution.
0
Vlad
Telerik team
answered on 23 Feb 2010, 01:40 PM
Hi,

Please post more info about your scenario and grid version.

Sincerely yours,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Saumil Shah
Top achievements
Rank 1
answered on 23 Feb 2010, 01:53 PM
I am following "Telerik RadChart for Silverlight - Integration - Grouping and Aggregation" example. Only difference is I am using dynamic data from database intead of fixed data in the example. I can see data correctly in teleric gridview but when i try to bind same data in chart ( RadChart1.ItemsSource = RadGridView1.ItemsSource;), it is giving me following runtime exception.

"An unhandled exception ('Unhandled Error in Silverlight Application
Code: 4004
Category: ManagedRuntimeError
Message: System.ArguementException: Invalid property or field - 'propertyName' for type: AggregateFunctionGroup.

Please let me know if you have any idea about the solution.
0
Saumil Shah
Top achievements
Rank 1
answered on 23 Feb 2010, 02:28 PM
Here is the solution.

If you are using grid paging then get your resultset in saparate variable. and instead of doing
RadChart1.ItemsSource = RadGridView1.ItemsSource
do following.
RadChart1.ItemsSource = _localVariable;

It has resolved my issue. I hope this will help.

Thanks.
0
Kirill Prokopenko
Top achievements
Rank 1
answered on 06 Apr 2010, 10:25 PM
Hi,

I had the same issue.  I had telerik grid bound to a collection of INotifyPropertyChanged objects. Collection was of type IEnumerable<INotifyPropertyChanged> but contained custom objects that implemented INotifyPropertyChanged interface and had extra properties. One of those properties was selected to get Summary aggregate function result. It failed exactly the same way described on the start of this thread.

To fix it, I had to bind data grid explicitly to IEnumerable<MyTypeThatContainsProperty>. After that everything works fine. Since I had a lot of possible types bound to grid, I created ValueConverter that converts my generic IEnumerable<INotifyPropertyChanged> into specific IEnumerable<> of any type required but, of course, this approach adds some restrictions.

I think the root cause is the fact (MAY BE) that when databinding is performed the property is taken from the GenericArgument collection of the items source's type instead of the object stored in the collection itself. Probably for better performance.

Hope this information will help others.
0
Jonx
Top achievements
Rank 2
answered on 21 Jun 2010, 05:13 PM
Hello,
I have the same problem. When I try to use an aggregate function that needs to access to a field...

The binding for the grid is
ItemsSource="{Binding ElementName=beneficiaryDomainDataSource, Path=Data}"

The datasourc is
<riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance domain:Beneficiary, CreateList=true}" Height="0" LoadedData="beneficiaryDomainDataSource_LoadedData" Name="beneficiaryDomainDataSource" QueryName="GetBeneficiariesQuery" Width="0" SubmittedChanges="beneficiaryDomainDataSource_SubmittedChanges">
            <riaControls:DomainDataSource.DomainContext>
                <domain:SoContext />
            </riaControls:DomainDataSource.DomainContext>
        </riaControls:DomainDataSource>

When I remove the datasource and use this in the page constructor to load my data it is working:
            LoadOperation<Beneficiary> op = this._context.Load(this._context.GetBeneficiariesQuery());
            grdBeneficiaire.ItemsSource = op.Entities;

But this is not an acceptable solution for me as it is less practical to use and also it is much slower...

Any work around?

I find this feature does not work as advertised or I did not understand how to use it...

If someone sent a sample to support, what was the answer?

Thanks...



0
Stefan Dobrev
Telerik team
answered on 22 Jun 2010, 01:57 PM
Hello John,

Recently we have fixed an issue when column aggregates were used and RadGridView was bound to DomainDataSource. Can you please download our latest internal build and verify the behavior on your side?

Kind regards,
Stefan Dobrev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jonx
Top achievements
Rank 2
answered on 22 Jun 2010, 04:05 PM
Hello Stefan,
I linked my project to the lastest build dlls (controls, data and gridview in my case) and I confirm that this solves the problem.

The aggregate functions work as expected. Even on calculated fields...

Thanks,
John.
Tags
GridView
Asked by
tungnt185
Top achievements
Rank 2
Answers by
Vlad
Telerik team
tungnt185
Top achievements
Rank 2
Saumil Shah
Top achievements
Rank 1
Kirill Prokopenko
Top achievements
Rank 1
Jonx
Top achievements
Rank 2
Stefan Dobrev
Telerik team
Share this question
or