I try to call EF method ToListAsync. But nothing happend - no exception, no timeout just running.
This is my code.
private IQueryable<Place> placeCompleteQuery;
protected IQueryable<Place> PlaceCompleteQuery
{
get
{
return this.placeCompleteQuery ?? (this.placeCompleteQuery = this.Context.Places.Include(p => p.Address).
Include(p => p.CreatedBy).
Include(p => p.Source).
Include(p => p.Type.Translations).
Include(p => p.Ratings));
}
}
public async Task<IList<Place>> GetPlacesByLocationAsync(DbGeography location, int radius)
{
List<Place> temporaryResult = PlaceCompleteQuery.Where(p => p.Location.Distance(location) <= radius).
ToList();
return await PlaceCompleteQuery.Where(p => p.Location.Distance(location) <= radius).
ToListAsync();
}
The first sync call of ToList method return result immediately. The second async call of ToListAsync still running with no result nor exception.
Any suggestions?
I suspect that further up your call stack, your code is calling Task.Wait
or Task<T>.Result
. If you do this on the UI thread or from an ASP.NET request context, your code will deadlock, as I explain on my blog.
To fix it, use await
instead of Task.Wait
or Task<T>.Result
.
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