views:

90

answers:

1

Hello,

I'm using RiaServices to populate a grid using an EntityQuery.

Since my database has millions of rows, I want to query only the current page, but also to bring the total number of rows for paging purposes.

Ex: 100 rows total

entityQuery.Skip(0).Take(10); //for the first page
entityQuery.IncludeTotalCount = true;

That brings me 10 rows, and loadOperation.TotalEntityCount = 100. Perfect.

But imagine this:

Ex: 100 rows total

entityQuery.Where(p => Id >= 1 && p.Id <= 50).Skip(0).Take(10); //with filter now
entityQuery.IncludeTotalCount = true;

That brings me 10 rows, and loadOperation.TotalEntityCount = 100 (I need 50!)

Here is the problem: for paging purposes, I need the total number of entities satisfying my filter, not all of them.

Is it possible to change the query for "IncludeTotalCount" or should I forget about TotalEntityCount and query the server two times?

Cheers,

André Carlucci

A: 

RIA Services handles total count requests by stripping off the skip/take paging directives (as you'd expect) and passing the unpaged query to the protected virtual DomainService.Count method. I recommend overriding this method, setting a breakpoint so you can verify that the correct count query is being passed to your service. If you're using the EF DomainService, the base implementation of Count will simply do a query.Count(). So things should be behaving as you expect - I'm not sure yet why they aren't. What type of DomainService are you using?

Mathew - MSFT
Oh dammit, I overrode this method long time ago and completely forgot its existence... I put a breakpoint there and caught the mistake. Tks.
andrecarlucci