How to: Retrieve paged data from a WebAPI service generated by the AOS wizard

Thread is closed for posting
1 posts, 0 answers
  1. 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 09 Jan 2013 Link to this post

    Requirements

    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.
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.