I've just realised that this code:
public async Task<List<Review>> GetTitleReviews(int titleID)
{
using (var context = new exampleEntities())
{
return await context.Reviews.Where(x => x.Title_Id == titleID).ToList();
}
}
...will not work as async methods cannot await LINQ expressions. I've did some searches but only managed to find some overcomplicated solutions.
How should functions which return LINQ expressions be converted to async versions?
Add the System.Data.Entity
namespace and take advantage of the Async
extension methods
In this case ToListAsync
should do the trick
using System.Data.Entity;
public async Task<List<Review>> GetTitleReviews(int titleID)
{
using (var context = new exampleEntities())
{
return await context.Reviews.Where(x => x.Title_Id == titleID).ToListAsync();
}
}
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