Adapter Paging Bug

Posts   
 
    
arschr
User
Posts: 893
Joined: 14-Dec-2003
# Posted on: 07-Nov-2013 17:30:32   

The documentation on paging says

Paging is disabled if you pass 0 for the page number or 0 or 1 for the page size.

My tests show it is not disabled, but instead treats a page number of 0 as if it were a page number of 1, honoring page size, rather than max number of records.

SD.LLBLGen.Pro.DQE.SqlServer: File Version 4.0.13.523 SD.LLBLGen.Pro.ORMSupportClasses: File Version 4.0.13.725

The following test passes all asserts, but the 3rd should fail,


[Test]
        public void PagingTest01()
        {
            using (var adapter = new DataAccessAdapter())
            {
                int maxRecords = 200;
                int pageNoZero = 0;
                int pageNoOne = 1;
                int pageSize = 100;
                var invoiceId = 479937;
                var rpb = new RelationPredicateBucket(LifelineDetailV2Fields.InvoiceId == invoiceId);
                var sortExpression = new SortExpression(LifelineDetailV2Fields.RowId | SortOperator.Ascending);
                var collection1 = new EntityCollection<LifelineDetailV2Entity>();
                var collection2 = new EntityCollection<LifelineDetailV2Entity>();
                var collection3 = new EntityCollection<LifelineDetailV2Entity>();
                var collection4 = new EntityCollection<LifelineDetailV2Entity>();
                adapter.FetchEntityCollection(collection1, rpb);
                adapter.FetchEntityCollection(collection2, rpb,maxRecords,sortExpression);
                adapter.FetchEntityCollection(collection3, rpb,maxRecords,sortExpression,pageNoZero,pageSize);
                adapter.FetchEntityCollection(collection4, rpb, maxRecords, sortExpression, pageNoOne, pageSize);

                Assert.AreEqual(517,collection1.Count);
                Assert.AreEqual(200, collection2.Count);
                Assert.AreEqual(100, collection3.Count);
                Assert.AreEqual(100, collection4.Count);

                var results = string.Format("collection1:{0}|collection2:{1}|collection3:{2}|collection4:{3}", collection1.Count, collection2.Count, collection3.Count,
                    collection4.Count);
                Console.WriteLine(results);
                Assert.AreEqual(collection3[0].RowId,collection4[0].RowId);


            }
        }
Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 08-Nov-2013 06:45:38   

Reproduced.

Whenever PageSize is used, it gets honored on favor of the maxRecords, even if the PageNo is 0.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Nov-2013 07:05:07   

That's right. If you see the source code, pageSize has precedence over maxNumberRows:

/// <summary>
/// Calculates the row skip / take values from the 3 values from the pre-v4 api.
/// </summary>
/// <param name="pageNumber">The page number.</param>
/// <param name="pageSize">Size of the page.</param>
/// <param name="maxNumberOfItemsToReturn">The max number of items to return.</param>
/// <param name="rowsToSkip">The rows to skip.</param>
/// <param name="rowsToTake">The rows to take.</param>
public static void CalculateRowSkipTake(int pageNumber, int pageSize, int maxNumberOfItemsToReturn, out int rowsToSkip, out int rowsToTake)
{
    rowsToTake = (pageSize <= 0) ? maxNumberOfItemsToReturn : pageSize;
    rowsToSkip = 0;
    if(pageNumber > 0)
    {
        rowsToSkip = rowsToTake > 0 ? ((pageNumber - 1) * rowsToTake) : 0;
    }
}

We will see into whether or not this is something to fix or just update the docs.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 08-Nov-2013 10:02:55   

Ah indeed. It should take pageSize over maxRows, because if paging is specified, maxrows has no meaning. However, it should only do that if the two paging values (pagesize, pagenumer) are both valid, otherwise they should be ignored.

A bug simple_smile Will fix.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 08-Nov-2013 10:54:49   

Fixed in attached dll.

Attachments
Filename File size Added on Approval
SD.LLBLGen.Pro.ORMSupportClasses.zip 412,145 08-Nov-2013 10:54.57 Approved
Frans Bouma | Lead developer LLBLGen Pro
arschr
User
Posts: 893
Joined: 14-Dec-2003
# Posted on: 08-Nov-2013 13:00:52   

Thanks, I'll test it.

arschr
User
Posts: 893
Joined: 14-Dec-2003
# Posted on: 05-Dec-2013 16:40:12   

Finally tested this (using v4.1) It is fixed

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 05-Dec-2013 17:11:27   

pfew simple_smile

Frans Bouma | Lead developer LLBLGen Pro