OData / OData/WebApi

Is there a way to skip pagination on nested collection

Open
#2,452 1 comment 0 reactions 1 assignee View on GitHub

@Sreejithpin is already working on this.

Since Mar 30, 2021.

question
Dominant language
C#
Stars
864
Forks
467
PR merge metrics
No merged PRs in 30d

Description

I have an API built using .netcore3.1 and OData which returns a collection of list and each item in the list has another collection property.

when i apply [EnableQuery(PageSize =10)] attribute on the controller method, i get odata response with 10 items. when i expand the collection property, if it has more than 10 records, it gets paginated as well.

I'm looking for a way to apply the pagination only for the main collection not the nested collection.

Assemblies affected

Microsoft.AspNetCore.OData 7.5.6

Expected result

Full set of nested collection property without nextLink ( please see the below actual result, i'm looking to have the all the books included in the respon)

Actual result
{
  "@odata.context": "https://localhost:5001/odata/$metadata#Author(Books())",
  "value": [
      {
          "EntityId": "1",
          "Name": "John"
          "Books": [
               {
                   "Name": "Test"
               }
           ]
      },
      {
        // omitted for brevity
       },
       {
          "EntityId": "10",
          "Name": "Tony"
          "Books": [
               {
                   "Name": "Test"
               },
               {
                   // omitted for brevity
                }
           ],
           "Books@odata.nextLink": "http://localhost:5000/odata/Author('10')/Books?$skiptoken=BookId-%2710%27"
       }
    
  ],
  "odata.nextLink": "http://localhost:5000/odata/Author?expand=Books&$skiptoken=EntityId-%2710%27"
}
Additional detail
app.UseEndpoints(endpoints => {
      endpoints.MapControllers();
      endpoints.EnableDependencyInjection();
      endpoints.Select().Filter().OrderBy().Count().Expand().MaxTop(100).SkipToken();
      endpoints.MapODataRoute("odata", "odata",  GetEdmModel(app.ApplicationServices));
});
//

private IEdmModel GetEdmModel(IServiceProvider serviceProvider)
{
    var odataBuilder = new ODataConventionModelBuilder(serviceProvider);
     odataBuilder.EntitySet<Author>("Author").EntityType.HasKey(x = x.EntityId);
     odataBuilder.EntitySet<Book>("Book");
     return odataBuilder.GetEdmModel();
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.