OpenAcces
version
|
Q3 2012 SP1
|
.NET version |
4.5
|
Visual Studio version |
2012
|
programming language |
C# and VB.NET
|
|
|
PROJECT DESCRIPTION
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 and
OpenAccessBaseApiController 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 class:
- 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 class:
- 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).
Prerequisites
- The Northwind database
- The Dynamic LINQ library
Hint: Some of the browsers cannot serialize the result JSON, so you could use the fiddler tool to debug the Web API services.