Mike Robbins

Sitecore Developer Blog

Follow me on GitHub

Sitecore Entity Service (SSC) Adding Paging

Recently I did a Sitecore User Group talk on Entity Service (video based on the talk available on Master Sitecore). I was asked there how you could extend Entity Service to including paging instead of using the standard GetAll() function.

Using my method of extending Entity Service and its repository pattern, as explained in this blog post. This blog post will explain how to add a new custom paged function for getting all entities.

The first stage is to add a new interface inheriting from the standard IRepository. Create a new GetAll overloaded method with parameters from page size and current page number.

Update the repository, instead of inheriting for the standard IRepository, inherit from your new repository. Implement the functionality of the new paged GetAll function to load the required entities.

Within the controller update the constructor to use the new repository. Create a new function with parameters for the page size and current page number. Decorate the function with the ActionName attribute. This ActionName defines part the URL of the service to the function.

As I mentioned in my previous post on Entity Service, the routing of custom functions follows the following format. "/sitecore/api/ssc/"{Controller-Namespace}/{Controller}/{ID}/{CustomActionName}. So when adding paging, we don't need the ID part of the URL, however we need to supply something for the routing to work correctly.

For example you could use a path like this to hit the action. "/sitecore/api/ssc/MikeRobbins-EntityServicePaging-Controllers/Entity/1/GetAllPaged?pageSize=1&page=1"

Demo Application

Demo application of custom paging is available on GitHub.