OnPerformSelect & OnPerformGetDbCount in One Query?

Posts   
 
    
luciusism
User
Posts: 119
Joined: 02-Jun-2007
# Posted on: 29-Sep-2007 03:23:29   

I'm binding a typedView to a grid control and have to supply both the data table (using the FetchTypedView method) and the result set count (using GetDbCount method)

What I was wondering if I could instead consolidate these 2 queries into one? I was thinking of merely doing a DataTable.Count, but apparently the GetDbCount is called before the OnPerformSelect, thus forcing the two queries (at least w/ Telerik RadGrid)

Has anyone ever found away to reduce this to one trip to the db? Or maybe I'm being too fastidious about this?

Thanks!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Sep-2007 06:33:50   

I don't know IMHO a way to achieve that. LLBLGenPro uses PerformDBCount to perform paging. So the call is necessary because the in-memory collection count may not be the same that the query resulset count.

David Elizondo | LLBLGen Support Team
luciusism
User
Posts: 119
Joined: 02-Jun-2007
# Posted on: 29-Sep-2007 18:42:08   

Thanks daelmo for your reply. You make a good point, but I'd imagine you could avoid doing a in-memory datatable.rows.count and instead pull the dbcount along with the original dataTable fetch?

But even if I could get the count along with the datatable in the same query, I still have the problem of the PerformDBCount happening BEFORE the OnPerfromSelect. Is this an LL issue or a Telerik RadGrid issue?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 01-Oct-2007 10:01:04   

PerfromGetDBCount is used for paging.

So if you are not using paging and you are returning all the rows in the database table, so you may just do nothing in PerformGetDBCount or return e.CountainedCollection.Count

But if you use paging, then you need to pass the PageSize and the PageNumber to the Fetch method, thus fetching a subset of rows from the database not all the rows. And also you need to display or know the number of pages a user might navigate within. And to know the number of Pages, then you should execute another query to the database to get the Coutn(*) of rows.

You might wish to disable paging in the DataSource but enable it in the grid. Thus letting the dataSource fetch all the records in the database and leave the paging stuff to the grid. In this case (which I don't recommend at all) you may use e.CountainedCollection.Count in the PerformGetDBCount method without executing another query.

luciusism
User
Posts: 119
Joined: 02-Jun-2007
# Posted on: 01-Oct-2007 20:38:18   

Thanks Walaa, that is exactly what I'm looking for!