开发者

Smart paging problem with RiaServices and entityQuery.IncludeTotalCount when filtering

开发者 https://www.devze.com 2023-01-17 23:06 出处:网络
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 pu

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.IncludeTota开发者_Python百科lCount = 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


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消