Print Page | Close Window

Bug in PagedRdbQuery?

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1818
Printed Date: 16-Apr-2024 at 2:00am


Topic: Bug in PagedRdbQuery?
Posted By: evanian
Subject: Bug in PagedRdbQuery?
Date Posted: 17-May-2010 at 2:10am
I have a PagedRdbQuery object, with its PagesShouldOverlap property set to False.  Its PageSize property is set to 15 (the exact value is unimportant here, however).

The problem is this.  As long as I call NextPage() on the PagedRdbQuery, it returns the expected number of entities - 15, in this case.  However, if I call PrevPage(), the number of entities returned is PageSize -1, or in this case, 14.  The last entity in the set  for that page (the set that had been returned for that page when NextPage() was called earlier) is now missing.  The same is true for any pages that you reach by calling PrevPage().  Worse, those entities stay missing even if you move into those pages by calling NextPage() from an earlier page. 

This issue does not occur if PagesShouldOverlap is set to True.


I wonder if this issue is one you've seen before?  Any help would be appreciated!  I'm using IdeaBlade assemblies with Runtime Version v2.0.50727.





Replies:
Posted By: davidklitzke
Date Posted: 17-May-2010 at 11:37am
I could not duplicate this behavior.  My code worked fine,  Try this (from Reference Help):
 

static void Main(string[] args)

{

PersistenceManager pm = PersistenceManager.DefaultManager;

// Query orders in descending date sequence.

RdbQuery aQuery = new RdbQuery(typeof(Order));

aQuery.AddOrderBy(Order.OrderDateEntityColumn, System.ComponentModel.ListSortDirection.Descending);

// Build a paged query to retrieve 10 items at a time.

PagedRdbQuery pagedQuery = new PagedRdbQuery(aQuery);

pagedQuery.PageSize = 10;

pagedQuery.PagesShouldOverlap = false;

while (true) {

EntityList<Order> orders = pm.GetEntities<Order>(pagedQuery);

Console.WriteLine("Current page = " + pagedQuery.CurrentPage.ToString());

Console.WriteLine("Order count for this page = " + orders.Count.ToString());

foreach (Order anOrder in orders) {

Console.WriteLine(" Order id = " + anOrder.Id.ToString());

}

// to stop the window from going away

Console.WriteLine("\n\nPress Enter to continue");

Console.ReadLine();

if (pagedQuery.IsLastPage) break;

// Advance the query.

pagedQuery.NextPage();

}

}

}

}



Posted By: evanian
Date Posted: 18-May-2010 at 3:47am
Thanks for the prompt reply.  I notice that your sample code doesn't include any calls to PrevPage(), which is where the problem occurs for me -- have you tried that?

When I adapt your code to suit my database  the problem recurs.    Here's the output, followed by the adapted code.

--------------------------------------------------------------------------------

Output:

Moving ahead one page...
Current page = 2
Employer count for this page = 10

Moving ahead one page...
Current page = 3
Employer count for this page = 10

Moving ahead one page...
Current page = 4
Employer count for this page = 10

Moving back one page...
Current page = 3
Employer count for this page = 9

Moving back one page...
Current page = 2
Employer count for this page = 9

Moving back one page...
Current page = 1
Employer count for this page = 9

Moving ahead one page...
Current page = 2
Employer count for this page = 9

Moving ahead one page...
Current page = 3
Employer count for this page = 9

Moving ahead one page...
Current page = 4
Employer count for this page = 9

Moving ahead one page...
Current page = 5
Employer count for this page = 10


--------------------------------------------------------------------------------

Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IdeaBlade.Persistence.Rdb;
using IdeaBlade.Persistence;
using Model;
using IdeaBlade.Rdb;
using System.Reflection;

namespace PagingTest2
{
    public partial class IdeabladeSample : Form
    {
        PagedRdbQuery _pagedQuery;

        public IdeabladeSample()
        {
            InitializeComponent();
            RunQuery();
        }


        private void RunQuery()
        {
            PersistenceManager pm = PersistenceManager.DefaultManager;

            // Query orders in descending date sequence.
            RdbQuery aQuery = new RdbQuery(typeof(AS400Employer));

            aQuery.AddOrderBy(AS400Employer.EmployerEntityColumn, System.ComponentModel.ListSortDirection.Descending);

            // Build a paged query to retrieve 10 items at a time.
            _pagedQuery = new PagedRdbQuery(aQuery);
            _pagedQuery.PageSize = 10;
            _pagedQuery.PagesShouldOverlap = false;

            MoveNext();
            MoveNext();
            MoveNext();

            MovePrevious();
            MovePrevious();
            MovePrevious();

            MoveNext();
            MoveNext();
            MoveNext();
            MoveNext();

        }

        private void MoveNext()
        {
            MoveQuery(true);
        }

        private void MovePrevious()
        {
            MoveQuery(false);
        }

        private void MoveQuery(bool forward)
        {
            // Move either foward or back
            if (forward)
            {
                WriteLine("Moving ahead one page...");
                _pagedQuery.NextPage();
            }
            else
            {
                WriteLine("Moving back one page...");
                _pagedQuery.PrevPage();
            }

            PersistenceManager pm = PersistenceManager.DefaultManager;

            EntityList<AS400Employer> employers = pm.GetEntities<AS400Employer>(_pagedQuery);
            WriteLine("Current page = " + _pagedQuery.CurrentPage.ToString());

            WriteLine("Employer count for this page = " + employers.Count.ToString());

            WriteLine("");

        }

        private void WriteLine(string s)
        {
            Console.WriteLine(s);

            if (txtDisplay.Text == "")
                txtDisplay.Text = s;
            else
                txtDisplay.Text += Environment.NewLine + s;
        }
    }
}



Posted By: foxs
Date Posted: 06-Jul-2011 at 8:26pm
I'm currently experiencing the same problem, any idea on how to fix this?


Posted By: kimj
Date Posted: 08-Jul-2011 at 10:32am
We've confirmed this as a bug.  Sorry, we don't have a workaround, other than to set overlap to true when possible.  We hope to have this fixed in the next release.



Print Page | Close Window