[英]EntityFramework ToListAsync() does not work
I try to call EF method ToListAsync. 我尝试调用EF方法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. ToList方法的第一次同步调用立即返回结果。 The second async call of ToListAsync still running with no result nor exception.
ToListAsync的第二次异步调用仍在运行,没有结果也没有异常。
Any suggestions? 有什么建议?
I suspect that further up your call stack, your code is calling Task.Wait
or Task<T>.Result
. 我怀疑你的调用堆栈更进一步,你的代码调用
Task.Wait
或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. 如果你在UI线程或ASP.NET请求上下文中执行此操作, 您的代码将会死锁 ,正如我在我的博客上解释的那样。
To fix it, use await
instead of Task.Wait
or Task<T>.Result
. 要修复它,请使用
await
而不是Task.Wait
或Task<T>.Result
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.