Getting Total count when calling a paged request

Posts   
 
    
gemfore
User
Posts: 35
Joined: 30-Jul-2010
# Posted on: 30-Jul-2010 12:43:11   

I'm hitting the db and only returning e.g. page 2 of 1000 and then binding that to a grid.

In order to know how many pages/records i have i'm havng to first run a GetDbCount and then a FetchEntityCollection.

Obviously this mean that im having to hit the db twice each time.

Is there an easy and efficent way combine this as one call like other O/R mappers?

Thanks Gemfore

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 31-Jul-2010 04:05:36   

There is no other way. To be honest I'm not familiar with other frameworks, when you say that they fetch the Count information in one shoot.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 31-Jul-2010 09:47:18   

It's done in 2 queries, but this is because we use internally two different pipelines: one for entity fetches and one for other projections. The 'count' value obtained in the 'same' query, would then have to be returned somewhere, which isn't what's intended when you fetch the data. It's also not really what you want ->

This is often used in paging (otherwise, do a count on the entity collection wink ), and to calculate the full count you have to execute a different query than the paging query in many situations. This means that it has to be 2 queries anyway. The advantage of doing it separately is that you can do a count once, and every subsequential page you fetch doesn't need to obtain the count as well as it never obtains the count in the collection fetch.

Frans Bouma | Lead developer LLBLGen Pro