AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

[Improvement] Add support for query batching when using $count=true

Open kerajel opened this issue 1 year ago • 0 comments

Given "Microsoft.AspNetCore.OData" Version="8.2.3" and async OData controller:

[EnableQuery]
public async Task<IAsyncEnumerable<Order>> Get()
{
    IQueryable<Order> queryable = _context.Orders;
    return queryable.AsAsyncEnumerable();
}

When I execute a query then I see 2 separate calls performed

  1. A synchronous request to fetch total count (the synchronous nature is itself another bug as described here: https://github.com/OData/WebApi/issues/2325
  2. An asynchronous request fetching the actual data

This resulted into 2 separate db roundtrips, however it could have been optimized by batching these 2 queries together as for example is possible via Entity Framework Plus Query Future: https://entityframework-plus.net/ef-core-query-future

Batching such requests together would reduce the amount of roundtrips to db and improve performance.

kerajel avatar Nov 26 '23 18:11 kerajel