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

10 posts, 0 answers
  1. Edward Pauley
    Edward Pauley avatar
    48 posts
    Member since:
    May 2010

    Posted 25 Jun 2011 Link to this post

    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
  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 26 Jun 2011 Link to this post

    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
  3. DevCraft banner
  4. Edward Pauley
    Edward Pauley avatar
    48 posts
    Member since:
    May 2010

    Posted 26 Jun 2011 Link to this post

    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
  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 27 Jun 2011 Link to this post

    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
  6. Edward Pauley
    Edward Pauley avatar
    48 posts
    Member since:
    May 2010

    Posted 27 Jun 2011 Link to this post

    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
  7. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 28 Jun 2011 Link to this post

    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
  8. Edward Pauley
    Edward Pauley avatar
    48 posts
    Member since:
    May 2010

    Posted 28 Jun 2011 Link to this post

    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
  9. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 29 Jun 2011 Link to this post

    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
  10. Josh Eastburn
    Josh Eastburn avatar
    32 posts
    Member since:
    Aug 2012

    Posted 19 Sep 2011 Link to this post

    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
  11. Edward Pauley
    Edward Pauley avatar
    48 posts
    Member since:
    May 2010

    Posted 19 Sep 2011 Link to this post

    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().
Back to Top
DevCraft banner