简体   繁体   中英

How can I get the page count of a PagedRdbQuery

I'm trying to get the max page count of a paged query so if I were to page data out on a form, say there's 300 data items and each page shows 100, then there's 3 pages, but in this case I don't know how many data items there are since it's always being added to. Is there a simple way I can use the PagedRdbQuery I'm using to get the data to get how many max pages there are?

So far I've tried

 private int GetMaxPagesOfRdbQuery(PagedRdbQuery query)
    {
        int pages = 0;
        query.CurrentPage = 1;
        while (!query.IsLastPage)
        {
            query.NextPage();
            pages += 1;
        } 
        return pages;
    }

however this returns the number "9999" every time which leads me to believe it will only give the correct number if I'm actually going through and getting all rows of data, which is impractical for me to do since some customers have data tables with upwards of a million records. Is there any other way I can use Ideablade to just get either the row count from my db or get the max pages?

Unfortunately, neither the PagedRdbQuery nor DevForce Classic offers a direct way to do this.

As a workaround you can obtain the item count in a separate query, but again it's not completely straightforward because Classic also doesn't provide a way to directly obtain aggregates. The simplest way to obtain the count might be with a DynamicEntity. For example, this retrieves the count of rows in an Employee table:

  var aType = DynamicEntityTypeBuilder.CreateType("Dummy", "yourdatasourcekeyname");
  var query = new PassthruRdbQuery(aType, "select count(*) ct from Employee");
  var entities = pManager.GetEntities<DynamicEntity>(query);
  var ct = entities?[0]?[0] as int?;

If using a DynamicEntity is too cumbersome another option is to use ADO.NET directly, possibly via an InvokeServerMethod if you need to keep DB access on the server tier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM