llblgenprodatasource and filtered total count

Posts   
 
    
glennpd
User
Posts: 30
Joined: 09-Feb-2006
# Posted on: 01-Aug-2006 17:31:27   

Since the llblgenprodatasource handles paging the llblgenprodatasource.entitycollection.count is never more than the pqge size specified by the binding grid. Is there any way to derive the complete filtered count from the llblgenprodatasource?

thanks

Glenn

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39926
Joined: 17-Aug-2003
# Posted on: 01-Aug-2006 18:32:01   

A bound control will call the ExecuteSelect routine twice: first for the count, then for the page. The count is then used by the bound control (e.g. a gridview) to display a page list.

In what context are you using the paging feature? Without a bound control?

Frans Bouma | Lead developer LLBLGen Pro
glennpd
User
Posts: 30
Joined: 09-Feb-2006
# Posted on: 01-Aug-2006 18:43:59   

Otis wrote:

A bound control will call the ExecuteSelect routine twice: first for the count, then for the page. The count is then used by the bound control (e.g. a gridview) to display a page list.

In what context are you using the paging feature? Without a bound control?

The DataSource is bound to a GridView control.

When I add the following

Protected Sub MyPerformGetDbCount(ByVal sender As Object, ByVal e As System.EventArgs) Handles LLBLGenProDataSource1.PerformGetDbCount
        Dim i As Integer
        i = 1
    End Sub


Build fails but does not report what the error is!!! I just wanted to test capturing the event.

Glenn

glennpd
User
Posts: 30
Joined: 09-Feb-2006
# Posted on: 01-Aug-2006 20:52:15   

What should the object signature be? I don't think it is sender as object and e as system.eventargs.

Glenn

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39926
Joined: 17-Aug-2003
# Posted on: 02-Aug-2006 19:04:23   

Could you elaborate a bit why you want to do what you want to do? As everything is taken care of for you.

If nothing helps: set LivePersistence to false and perform the GetDbCount yourself in the code behind. This way you can grab the count yourself and use it to do things on the page.

Frans Bouma | Lead developer LLBLGen Pro
glennpd
User
Posts: 30
Joined: 09-Feb-2006
# Posted on: 03-Aug-2006 18:15:20   

Otis wrote:

Could you elaborate a bit why you want to do what you want to do? As everything is taken care of for you.

I need to display a total count of the records filtered, not just the records currently presented in the grid. There does not seem to be a propery in the llbdlgenprdatasource for the result of the filtered set. Of course there is a count property of the entity collection but this represents the subset of records in the current page of a paged grid.

Glenn

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39926
Joined: 17-Aug-2003
# Posted on: 03-Aug-2006 18:18:08   

I needed exactly that. See my example below. It uses LivePersistence=false:


protected void _customerDS_PerformGetDbCount(object sender, PerformGetDbCountEventArgs e)
{
    int count = e.ContainedCollection.GetDbCount(e.Filter);
    e.DbCount = count;
    _rowCountLabel.Text = count.ToString();
}

protected void _customerDS_PerformSelect(object sender, PerformSelectEventArgs e)
{
    e.ContainedCollection.GetMulti(e.Filter, e.MaxNumberOfItemsToReturn, e.Sorter, e.Relations, e.PrefetchPath, e.PageNumber, e.PageSize);
}

(selfservicing)

Frans Bouma | Lead developer LLBLGen Pro
nato24 avatar
nato24
User
Posts: 14
Joined: 10-Apr-2007
# Posted on: 10-Apr-2007 20:16:11   

First off; thanks for all your support in these forums!

I am using a LLBLGenProDataSource control with my gridview (paging enabled, self service). I have set live persistence to false.

Is there a better way of getting the filtered record count?

This is what I'm using, but just don't like the fact that it requires 2 trips to the database.


        protected void OrderDataSource_PerformSelect(object sender, PerformSelectEventArgs e)
        {
            OrderDataSource.EntityCollection = Order.GetOrderHistory(SessionHelper.UserKey, e.PageNumber, e.PageSize);
        }

        protected void OrderDataSource_PerformGetDbCount(object sender, PerformGetDbCountEventArgs e)
        {
            e.DbCount = e.ContainedCollection.GetDbCount(e.Filter);
        }

Any suggestions?

Thanks, Nathan

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Apr-2007 09:48:21   

The count should be the same as the Count property of the EntityCollection fetched in the PerformSelect event handler.

nato24 avatar
nato24
User
Posts: 14
Joined: 10-Apr-2007
# Posted on: 11-Apr-2007 16:41:11   

Right, but...

The **PerformGetDbCount **event fires before PerformSelect. I can't bring back the entity collection in the **GetDbCount **event because I don't have access to the **PageSize **and **PageNumber **eventarg properties.

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Apr-2007 16:48:47   

I got you. I think you can't reduce the database hits, unless you give up the out-of-the-box paging feature.

nato24 avatar
nato24
User
Posts: 14
Joined: 10-Apr-2007
# Posted on: 11-Apr-2007 17:21:10   

Thanks for your help Walla.

If anyone finds a creative solution to this, please post.

Thanks