I'm developing an ASP.NET MVC application using RavenDB 3. I don't have a lot of experience with raven.
In general, when executing queries to display data, the first 128 items are returned on the page. More records are added in an "infinite scroll"-manner by using paged queries.
Now, however, I have the requirement that items are loaded in 'groups'.
Assume the following class:
public class Item {
public string Id { get; set; }
public int Group { get; set; }
public string text { get; set; }
}
Assume the database contains 40 items having group='1', 40 items having group='2' and 50 items having group='3'.
This is a total of 130 items. This would mean that the last 'group' fetched would not be complete. It would be missing 2 items.
I would like a mechanism that is aware of this, so that it would fetch at least 128 AND would fetch 'extra' if the last group is not completely included.
Afterwards, when I fetch the next page, I would like it to start with the next group.
Is there any way I can make this work without 'fabricating' a single page myself by doing more than one call?
EDIT: I cannot assume the groups are perfectly equal in size, but I can assume the sizes will be 'simular'
Also, I cannot change the design to store all items in a single 'group'-object for instance.
Okay so basically what you will need to do is calculate the number of results that were in the previous pages and the number of results that are in the current page. Below is a quick example app to give you an idea of how to do it. One caveat, if the number of results for the current group range exceeds the
MaxNumberOfRequestsPerSession
than an error will be thrown, so you might want to put some handling in there for that.Note for running this example: Make sure your platform is set to x64 in visual studio if you are using the most recent versions of RavenDB. Otherwise, this example will thrown an error about Voron not being stable in 32 bit mode.