I am implementing async programming in ASP.NET Core-6 Web API.
I have this code:
public async Task<IQueryable<Score>> GetExamScoreAsync(PagingFilter filter)
{
var examScores = _dbContext.Scores
.Where(m => (bool)m.Approval.IsFirstLevel == false)
.Where(x => string.IsNullOrEmpty(filter.SearchQuery)
|| x.Subject.ToLower().Contains(filter.SearchQuery.ToLower())
|| x.StartDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture).Contains(filter.SearchQuery.ToLower())
|| x.EndDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture).Contains(filter.SearchQuery.ToLower()))
.OrderByDescending(x => x.CreatedAt);
return examScores;
}
I got this warning:
Severity Code Description Project File Line Suppression State Warning CS1998 This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work
When I added await before _dbContext.Scores, I got this error:
Error CS1061 'IOrderedQueryable' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'IOrderedQueryable' could be found (are you missing a using directive or an assembly reference?)
How do I get this sorted out and apply async here?
Thank you.