WebAPI OData v4 requests not async?

I searched the answer to find the answer to this question, but I can not find the final answer. We use OData v4 using ODataQueryOptions.Apply to apply OData parameters to the query. We also use ODataQuerySettings to set the page size. When we set the page size, we can no longer use ToListAsync () in IQueryable, which is returned from ODataQueryOptions.ApplyTo. The error message says that the IQueryable provider is no longer from the Entity Framework.

I found that this is due to the fact that when using pages, OData allows IQueryable by passing it through the TruncatedCollection. This TruncatedCollection fetches all (pagesize + 1) results from the database to check if there were more results than the results. However, ApplyTo is not an asynchronous method, so I can safely assume that this database query is not executed asynchronously.

Is there something I can do to make sure the request is asynchronous? Did the OData Team Think About This? Or is it normal for it to be synchronous as it is? It seems to me that asynchronous IO is almost necessary these days, since we want our API to scale well and not block all our threads, waiting for I / O.

Thanks for the help!

Change 1:

I was asked to give some code to explain what I mean.

In BaseController.cs:

public class BaseController : ODataController
{
    private static readonly ODataQuerySettings DefaultSettings = new ODataQuerySettings() { PageSize = 60 };


    protected Task<IHttpActionResult> ODataResult<T>(IQueryable<T> query, ODataQueryOptions<T> options)
    {
        IQueryable result = options.ApplyTo(query, DefaultSettings);
        return Task.FromResult(ODataOk(result));
    }
}

In CustomerController.cs:

public class CustomerController : BaseController
{
    ICustomerService customerService;

    public async Task<IHttpActionResult> Get(ODataQueryOptions<Customer> options)
    {
        var query = customerService.Query();
        return await ODataResult(query, options);
    }
}

As I said above, the problem is with the ApplyTo base code. This is a method from OData itself. Line:

    IQueryable result = options.ApplyTo(query, DefaultSettings);

already querying the database due to the fact that we are defining the page type in DefaultSettings. Determining the page type causes the base code in the ApplyTo application to retrieve all the data from the database and then return the list as requested. This means that the database is queried in a synchronous function.

So my question is: is there a way to implement swap in OData without giving up reading async? Or am I feeling too hard when I try to do this?

+4
2

OData, . IQueryable. IQueryable.Take IQueryable.ToListAsync( ).

Microsoft Web Api OData v4 , . . . ODataQuerySettings.ApplyTo TruncatedCollection. TruncatedCollection System.Collections.Generic.List IQueryable , IEnumerable, .

, Web Api OData ( ), . ODataQuerySettings.ApplyTo, .

0

, ToListAsync(). . , . , . IQueryable . ( OData , ).

, IQueryable ( IEnumerable, ) (. ). .

, Odata , . , , Odata .

-3

All Articles