2
votes

Here is my ODATA controller with an ODATA action.

   public class MyController : ODataController
{
    private readonly Repository_repo;

    public MyController(IRepository repo)
    {
        _repo = repo;
    }

    [EnableQuery(PageSize = 10, EnsureStableOrdering = false)]
    public IActionResult Get()
    {
        var data = _repo.GetData();
        return Ok(data)

    }

}

Here is my Repository method.

   public IQueryable<DataModel> GetData() => _db.DbSet.Select(data=> new DataModel
    {
        // Implement model
    }).

Now I understand there is no point making the GetData method in the repo as async because that is just returning a queryable which doesn't get executed till you call it's enumerator.

So the part to make async is the action method. How would I make this an async await- able call? Odata EnableQuery method expects an IQueryable as far as I am aware.

1

1 Answers

1
votes

You do not need to. The action method is just one part of the request pipeline; it not being async does not preclude other things in the pipeline from being async. The middleware that's processing the OData query is what is actually sending the query to the database, and very likely does so async (I'm not familiar with source code, and cannot say definitively). Regardless, your action need only be async if you're actually doing something async in it. Otherwise, don't worry about it.