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

Call service(ria,or wcf, or ,...) basing on filters of DataFilter to retrieve the total sum (not paging result)

9 Answers 62 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
Edward Pauley
Top achievements
Rank 1
Edward Pauley asked on 26 Jun 2011, 02:35 AM
Hi

I am using Entity framework , RIA Sevice(or wcf service)
i have an Entity "Customer": which has the fields
-CustomerFirstName string
-CustomerLastName string
-Allowance decimal

the problem with this Customer table is that it has around 400k data in my table
i am using RadDatafilter +RadDomainDataSource + RadGridview  to retrieving the data Customers row for the radgridview
Due to large amount of data, i have to enable the RadDataPager(assuming 10 data per page)

However, my real problem is that i don't want to show the total sum of "Allowance" for each page(sum of 10 rows). I want to display the total sum of Allowance of all my customer in the database (around 400k)
In order to do that, i make an extra Service  beside the query of the raddomaindatasource (so 2 services now).This extra service will do the job of finding the total sum of allowance

Here is where i get stuck:
whenever the user uses the raddatapager to filter the result of the radgridview(paged by radDataPager), i don't want to display the total sum "Allowance" of only one page. I want to display the sum of allowance of all the possible filter result in database
Meaning that if the filtered result produces around 100k data and the radgridview only show 10 data per page, I want to display the total sum "Allowance" of 100k filter data.


can you show me an example of how doing that?

thanks

9 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 26 Jun 2011, 10:56 AM
Hello Edward Pauley,

I am afraid that you cannot do that. You will have to devise some kind of custom logic that will go to the server and get that number and then display it somewhere outside of RadGridView. RadGridView has no intrinsic knowledge that there is a server and that there are actually more rows than the 10 rows it is currently displaying. For RadGridView, its ItemsSource is something that has 10 rows and that's the only thing it cares about, so there is no way for RadGridView to "know" the bigger picture and show aggregates on something which is not part of its ItemsSource. 

I hope this makes sense.

Greetings,
Ross
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
Edward Pauley
Top achievements
Rank 1
answered on 26 Jun 2011, 10:22 PM
hi Ross

i did realize that and i don't mind to have another seperated textbox to just show the total sum of Allowance for the filtered result
However, how can i build such an dynamic service basing on the filter operators selected by user on the radDataFilter
For example:
if the user uses the raddatafilter to create some filters such as :
FirstName StartWith "s"
and
Allowance IsGreaterThan 100
and
LastName Contain "h"

then i need to know how to use that information to call the service with matching above filters + Sum(a=>a.Allowance) to return the total filtered sum of Allowance


thanks
0
Rossen Hristov
Telerik team
answered on 27 Jun 2011, 08:33 AM
Hi Edward Pauley,

We have several extension methods in the Telerik.Windows.Data assembly in the static class Telerik.Windows.Data.QueryableExtensions. There are several Where methods that you can use to apply the FilterDescriptors over an IQueryable, in case you are using plain old WCF Data Services. So you can take your DataServiceQuery and feed it to this method. The method should "append" the filtering information from the FilterDescriptors and return you the new DataServiceQuery.

In case you are using WCF RIA services, where the EntityQuery<T> is not an IQueryable, we have a similar Where method in the Telerik.Windows.Controls.DomainServices assembly in the Telerik.Windows.Controls.DomainServices.EntityQueryExtensions class. This Where method accepts and EntityQuery<T> and a collection of FilterDescriptors and with the help of some expression visitor magic will return a new "filtered" EntityQuery.

I hope this helps.

Best wishes,
Ross
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
Edward Pauley
Top achievements
Rank 1
answered on 27 Jun 2011, 11:53 PM
Hi Ross,

i saw the extension method Where clause in your assembly and be able to create the new filtered query basing on what user chooses for the filter operators on RadDataFilter

EntityQuery filteredEntityQuery = myContext.GetCustomersQuery().Where(radDataFilter1.FilterDescriptors);

However, as from my original problem, for this extra service i don't want to retrieve the filtered Customer(too much data for doing that , and my radgridview already use another service which has paging to do the job already)

. I only want to return the total allowance of filtered customer

so i want something like this (but definitely this code won't work)
filteredEntityQuery.Sum(c=>c.Allowance);

thanks
0
Rossen Hristov
Telerik team
answered on 28 Jun 2011, 08:34 AM
Hello Edward Pauley,

I see, but how is that question specifically related to Telerik controls? How would you go about doing the same thing if you were using another grid?

Maybe the gurus at the WCF RIA Services forums know how you can achieve that.

I hope this makes sense.

Greetings,
Ross
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
Edward Pauley
Top achievements
Rank 1
answered on 28 Jun 2011, 06:22 PM
Hi Ross,

I know this does not relate to telerik component. However, I hope you might have some useful information to advise me how to do that
because this feature is very critical to my current project
thank you
0
Rossen Hristov
Telerik team
answered on 29 Jun 2011, 08:00 AM
Hello Edward Pauley,

I wish I could help, but I am really no WCF RIA Services guru so my suggestion is to ask the guys on the WCF RIA Services forums -- lots of people from Microsoft post there. After all, WCF RIA Services is provided and supported by Microsoft, isn't it? The people that wrote it actually post on the forums. Use them.

All the best,
Ross
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
Josh Eastburn
Top achievements
Rank 1
answered on 19 Sep 2011, 02:57 PM
Hi Edward,

Did you have any success in finding a solution to this scenario?
I am working on implementing a very similar setup with reusing FilterDescriptors for a new query, but I want to get the Sum rather than all of the entities.  It seems like it needs to be a filtered Invoke command.

Josh
0
Edward Pauley
Top achievements
Rank 1
answered on 19 Sep 2011, 11:16 PM
Hi Josh,

for my scene, on the service server side i have to build the dynamic Expression tree manually basing on the filter descriptors of the RadDataFilter.

You should look at how to build an Expression Tree and transform that expression tree into the query so you can use it to build the Asqueryable().
Tags
DataFilter
Asked by
Edward Pauley
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Edward Pauley
Top achievements
Rank 1
Josh Eastburn
Top achievements
Rank 1
Share this question
or