Paging using Adapter

Posts   
 
    
KastroNYC
User
Posts: 96
Joined: 23-Jan-2006
# Posted on: 27-Jul-2007 19:36:37   

Using LLBL v2.5 July 23 buld.

Can someone please provide an example of paging both the PerformSelect and PerformDbCount events.

I understand performselect but getting PerformDbCount is confusing, should I return the ContainedCollection.Count or refetch from the db just for the count? is there another way? BTW, I am using the Manager Templates.

Right now I am implementing paging but it seems to be returning the full result set and then just moving to the set of results needed for display.

I have LivePersistance=false.

BTW - Right now from what i think is caused because I am not implementing GetDbCount, when I try to page I get a Internet Explorer cannot display this webpage message which is quite weird.

Thanks all.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 28-Jul-2007 05:34:26   

Hi Kastro, If you want to use server-side paging you need implement PerfomGetDbCount:

protected void MyDataSource2_PerformGetDbCount(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformGetDbCountEventArgs2 e)
    {
        using (DataAccessAdapter da = new DataAccessAdapter())
        {
            e.DbCount = da.GetDbCount(e.ContainedCollection, e.Filter);
        }
    }

Le me know if you can make it.

David Elizondo | LLBLGen Support Team
KastroNYC
User
Posts: 96
Joined: 23-Jan-2006
# Posted on: 30-Jul-2007 07:37:57   

It seems to work now using DbGetCount but the when I debug i can see the collection contains a total of 2900 results but when i then bind that result set to a grid i only see the first record. Any idea why that might occur?

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 30-Jul-2007 10:12:13   

It's recommended that you enable Paging on the LLBLGenProDataSource.

In this case LLBLGenProDataSource, will only fetch entities which belong to the requested Page. (Page number).

When you are using LivePersistence (= true), everything is done for you, the PageNumber & PageSize is passed from the Grid to the LLBLGenProDataSource automatically. And the Number of Pages is calculated by the LLBLGenProDataSource and then passed to the Grid.

But when you are not using LivePersistence (= false): 1- you should pass the requested PageNumber & PageSize to the Method fetching the entities. (in the Perform_Select event). And these are passed to the Perform_Select in the eventArgument parameter. (e.PageNumber, e. PageSize).

        protected void Categories_DS_PerformSelect(object sender, PerformSelectEventArgs e)
        {
            e.ContainedCollection.GetMulti(e.Filter, e.MaxNumberOfItemsToReturn , new SortExpression(CategoryFields.CategoryName | SortOperator.Ascending), e.Relations, e.PageNumber, e.PageSize);
        }

2- You should count the number of entities (used with the page size to determine the number of pages.) To do this you should call GetDbCount(), to count all numbers in the database, instead of getting the count of the fetched entityCollection, which in this case will only contain entities for one page.

        protected void Categories_DS_PerformGetDbCount(object sender, PerformGetDbCountEventArgs e)
        {
            // When enabling paging in the datasource, 
            // Don't get the entities count from the already fetched collection.
            // these would be only those belonging to the first page.
            //e.DbCount = e.ContainedCollection.Count;

            // Get the count of all entities in the database
            e.DbCount = e.ContainedCollection.GetDbCount();
        }

Otherwise if you don't enable paging in the datasource and you just enabled paging in the Grid control, then LLBLGenProDataSource will fetch all entities in the database and the paging will be done in the Grid. So you don't need to pass the PageNumber nor the Page Size to the fetching method. And you may get all entities count from the Fetched entityCollectiuon count.

Of-course this is not recommended as then you will fetch all entities in the database each time you request to view one page of them.