Paging using start&count instead of pageNumber&pageSize

Posts   
 
    
happyfirst
User
Posts: 215
Joined: 28-Nov-2008
# Posted on: 21-May-2013 23:10:50   

Switching to a new ajax grid, but this grid doesn't work in terms of pageNumber and pageSize. Since the user can scroll to anywhere in the grid and then it tries to load just those rows, I am seeing requests that basically are asking for N number of rows starting from X start index and X can be anything.

I've tried to do some math to convert start,count to pagenumber,pageSize, but ugggh, my math days are behind me. I was trying to send pageNumber to 2, pageSize to whatever the start index was, and then maxRows to the rows I really want back, but then that doesn't work if I'm requesting 50 rows starting at index 12.

What's the best way to solve this problem?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-May-2013 08:13:56   

What LLBLGen version are you using? LLBLGen API or Linq2LLBL?

(Edit) With Linq2LLBL you can use .Skip(n).Take(m) where n and m could be anything (more info...).

David Elizondo | LLBLGen Support Team
happyfirst
User
Posts: 215
Joined: 28-Nov-2008
# Posted on: 22-May-2013 14:58:48   

Sorry, it's been a while, forgot the protocol.

Using LLBL 3.1, Adapter model with sql server.

I have a lot of reflection based code inside a framework that uses base classes. If 3.1 supports that linq2llbl, is it possible i can generically call skip, take on a generically activated strongly typed collection with a predicate, etc?

I have managed to come up with an algorithm to convert startAt,count into pagenum,pagesize, but it's very ugly, may still have issues and I would still prefer to more directly just load records via a startAt,count approach.

Since internally, llbl is converting pagenum,pagesize into start and end, it would be nice if there was a way to just call it like that.

Another thing I like about startAt,count is that I can always request one more row than I really need so that I can set a flag indicating that there are more rows available. I had to customize another project's llbl pro library to help me do that. It would be a cool feature if FetchCollection could somehow return a boolean indicating if there are more rows or not.

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 22-May-2013 19:14:28   

If you are using v.3.1, I highly recommend upgrading to v.3.5 (free upgrade), and almost seamlessly.

If 3.1 supports that linq2llbl, is it possible i can generically call skip, take on a generically activated strongly typed collection with a predicate, etc?

Could you give an example please?

happyfirst
User
Posts: 215
Joined: 28-Nov-2008
# Posted on: 23-May-2013 20:39:39   

Here's a very simplified example:


 IDataAccessAdapter da = (IDataAccessAdapter) Activator.CreateInstance(adapterType);
IEntityCollection2 searchResults = (IEntityCollection2) Activator.CreateInstance(collectionsType);
da.FetchEntityCollection(searchResults, null, 0, sort, null, null, pageNumber, count);

Doing reflection on linq seems to be a lot harder. Would I be able to accomplish the above but through linq via reflection and then I could make use of the skip and take?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 24-May-2013 16:23:53   

happyfirst wrote:

Switching to a new ajax grid, but this grid doesn't work in terms of pageNumber and pageSize. Since the user can scroll to anywhere in the grid and then it tries to load just those rows, I am seeing requests that basically are asking for N number of rows starting from X start index and X can be anything.

I've tried to do some math to convert start,count to pagenumber,pageSize, but ugggh, my math days are behind me. I was trying to send pageNumber to 2, pageSize to whatever the start index was, and then maxRows to the rows I really want back, but then that doesn't work if I'm requesting 50 rows starting at index 12.

What's the best way to solve this problem?

In v4 we implemented what you want with a true skip/take implementation, so you can do Skip(12).Take(50).

In v3.x this isn't possible however, so you are tied to the pagenumber + pagesize combination.

Frans Bouma | Lead developer LLBLGen Pro
happyfirst
User
Posts: 215
Joined: 28-Nov-2008
# Posted on: 08-Jul-2013 18:11:00   

SelfServicing

I've downloaded the 4 trial but GetMulti still only accepts PageNumber and PageSize.

Is skip/fetch only for the linq layer?

I have a framework that uses reflection on an entitytype, entitycollectiontype, finds the GetMulti method, and dynamically makes the call to load data.

How can I do the same thing generically using reflection on the linq layer to make use of skip/fetch?

Any plans to add more overloads to GetMulti to accept startrow, endrow? Or skiprows, fetchrows?

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 09-Jul-2013 07:54:16   
var metadata = new LinqMetaData();
var q = (from c in metaData.Customer select c).TakePage(2, 20);

So for a CustomerEntity, you will need to use reflection on the LinqMetaData class to capture the corresponding Customer property.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 09-Jul-2013 08:22:15   

happyfirst wrote:

SelfServicing

I've downloaded the 4 trial but GetMulti still only accepts PageNumber and PageSize.

Is skip/fetch only for the linq layer?

You can also use it with the LLBLGen API. Try this:

var customers = new CustomerCollection();
var queryParameters = new QueryParameters();
queryParameters.CollectionToFetch = customers;
queryParameters.RowsToSkip = 3;
queryParameters.RowsToTake = 10;

customers.PerformGetMulti(queryParameters);
David Elizondo | LLBLGen Support Team