I've been trying to make the following controller method asynchronous
public IQueryable<Category> GetCategories()
{
return _context.Categories;
}
I've added the following to make it asynchronous
public async Task<IQueryable<Category>> GetCategories()
{
return await _context.Categories;
}
The type System.Data.Entity.DbSet is not awaitable
I'm not sure how to get the db context to return all the entities while maintaining the IQueryable.
How do you make the above method asynchronous? Thanks or the help.
It sounds like you're implementing an OData endpoint. If you do it at this level (returning a DbSet
directly from your controller), the asynchronous nature is entirely up to WebAPI; all you're doing is returning it an IQueryable
that it can use synchronously or asynchronously.
There's nothing you can do to "make" it asynchronous, and there's no reason to.
This is the solution I found:
public async Task<IEnumerable<Category>> Get(ODataQueryOptions<Category> options)
{
var myQueryable = (IQueryable<Category>)options.ApplyTo(context.Categories);
return await myQueryable.ToListAsync();
}
It works async and applies the filter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With