One of things that came up repeatedly in our API Reviews for RIA Services was the fact that, we were requesting the total server count of the resulting query by default for paging scenarios.
This basically meant that were executing two queries on the database:-
This was never an issue for most non-paging scenarios as the framework was optimized for it. Here is the flow in the previous releases:-
1: loadOp = ds.Load<Customer>(ds.GetCustomersQuery());
2: loadOp.Completed += new EventHandler(loadOp_Completed);
The count for this query would by 91 entities and the total entity count will also be 91 (No of customers in Northwind database).
In the latest RIA Services bits, we made a change where the count is not returned by default for paging scenarios.
Running a query like the one specified above will not have affect on the count and only one query will be executed on the server.
Now let’s modify the query to look like this and run it on the RC bits:-
loadOp = ds.Load<Customer>(ds.GetCustomersQuery().Take(10));
loadOp.Completed += new EventHandler(loadOp_Completed);
Now let’s look at the count returned from the server:-
As you can see the TotalEntityCount is –1.
So now the question arises is that how do i get the count when i add a take. All you need to do is to set the IncludeTotalCount property to true on the EntityQuery. Here is an example to do that:-
EntityQuery <Customer>loadCustomers = ds.GetCustomersQuery();
loadOp = ds.Load<Customer>(loadCustomers.Take(10));
Here are the results:-
DomainDataSource has been optimized to take this change into account and it will not request for count in non-paging scenarios. As soon as a page size is specified, DomainDataSource will set the IncludeTotalCount property on the EntityQuery for you. You can always override this behavior by subscribing to the LoadingData event on the DomainDataSource.
can that value be found somewhere else? as a property of the DomainDataSource components so that I can bind to it?
I was able to write the code in VB but how do I display the Total Count in a textbox?