Q3 2012 SP1
|Visual Studio version
C# and VB.NET
In order to retrieve paged data from a Web API service generated by the Add OpenAccess Service wizard you need to extend some of the generated classes with a few additional methods.
This project demonstrates how to manually extend the OpenAccessBaseRepository
partial classes, so that you can get paged data in one of the following manners:
The solution includes two new method definitions in the IOpenAccessBaseRepository<TEntity, TContext>
interface that are implemented in the OpenAccessBaseRepository
- GetAllWithoutDetaching() – gets the records without detaching them from the context, and
- DetachEntities(…) – that detaches the necessary records.
and two new overloads of the GetAll method in the OpenAccessBaseApiController
- GetAll(int skip, int take)
- GetAll (int skip, int take, string orderBy)
The new GetAll methods return a new custom object implemented in the PagingResponse
class. It contains a result set of records and their total number in the database (on which you could base the paging).
- The Northwind database
- The Dynamic LINQ library
: Some of the browsers cannot serialize the result JSON, so you could use the fiddler tool to debug the Web API services.