4 Answers, 1 is accepted
Retrieving paged data from a Web API service generated by OpenAccess ORM is not currently supported out of the box but we are planning to implement it in some of our future versions.
For your convenience I prepared a bare bone project demonstrating a workaround that is using methods instead of the canonical OData queries.
The sample is using the Northwind database and the Dynamic LINQ library. There are two manually added methods in the OpenAccessBaseRepository partial class - one to get the records without detaching them and one to detach records. Also there are two added overloads of the GetAll method in the OpenAccessBaseApiController partial class:
- Get paged data without sorting:
GetAll(
int
skip,
int
take)
- Get paged data sorted by custom properties:
GetAll (
int
skip,
int
take,
string
orderBy)
The methods are returning a new custom object which is containing a result set of records and their total number in the database (on which you could base the paging).
At the attached images you could find the new classes and examples for using the above-mentioned methods.
Please bear in mind that some of the browsers cannot serialize the result JSON, so you could use the fiddler tool to debug the Web API services.
I hope this is applicable for you.
Regards,
Dimitar Tachev
the Telerik team

Brian

I've stumble into your post while I am searching for OpenAccess - Web Api Paging.
Question:
1. I am using Telerik.OpenAccess (Version 2013.2.611.1) has this paging been fix?, I was trying to take the sample code and paste it inside my project to implement skip/take but there are a lot of changes.
2. I am getting Out of Memory in the Following Code in OpenAccessBaseRepository.cs
I know that it is try to return all records (186,137)
How can stop the user from requesting GetAll , if it is too many record ?
public virtual IQueryable<TEntity> GetAll()
{
List<TEntity> allEntities = dataContext.GetAll<TEntity>().ToList();
I am using C# Client to Consume the Web API from the following Sample.
http://www.asp.net/web-api/overview/web-api-clients/calling-a-web-api-from-a-net-client
3.
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:12345/");
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync(string.Format("api/DocList/{0}", this.textBoxId.Text)).Result;
Result Return 1 Row the Following is Working:
var p = response.Content.ReadAsAsync<DocList>().Result;
Result Return 1 Row the Following is NOT WORKING (Following the Sample in www.asp.net .. above) :
var docs = response.Content.ReadAsAsync<IEnumerable<DocList>>().Result;
// Parse the response body. Blocking!
foreach (var p in docs)
{
this.label1.Text = string.Format("{0}\t{1};\t{2}", p.Id, p.description, p.createdate);
}
Could you please point me to a sample of ASP.NET MVC C# Grid Consuming Web API.
Thank you
Regards Dat.
Please find the answers to your questions below:
1) The ASP.NET Web API paging is still not implemented out of the box but the sample application should be still applicable for this scenario because there are not any breaking changes in our Web API service generation.
For you convenience I prepared another example demonstrating this approach using our latest release - the Q2 2013 SP1 - please find it attached.
2) The out of memory exception is caused by the materialization of your query containing too many records.
In order to avoid this exception I suggest you add a limitation of the records returned as the one below:
public
virtual
IQueryable<TEntity> GetAll()
{
List<TEntity> top100Entities =
dataContext.GetAll<TEntity>().Take(100).ToList();
List<TEntity> detachedEntities = dataContext.CreateDetachedCopy<List<TEntity>>(top100Entities, fetchStrategy);
return
detachedEntities.AsQueryable();
}
3) Reviewing the code that you provided us I suppose that this issue is caused by the response object initialization and usage. It is initialized as:
HttpResponseMessage response = client.GetAsync(
string
.Format(
"api/DocList/{0}"
,
this
.textBoxId.Text)).Result;
.ReadAsAsync<DocList>()
If you need to use the
.ReadAsAsync<IEnumerable<DocList>>()
api/DocList/
Regarding a sample application demonstrating the Telerik OpenAccess ORM integration with the ASP.NET Web API services you could download our Samples Kit containing a lot of end-to-end sample applications and take a look at its ASP.NET Web API and ASP.NET MVC categories.
I suggest you take more attention at the ASP.NET Web API with WPF MVVM example which is using a very similar approach and client for consuming the Web API service.
I hope this helps. Do not hesitate to contact us back if you need any further assistance.
Regards,
Dimitar Tachev
Telerik