EntityFramework ToListAsync() funktioniert nicht
Ich versuche zu nennen, EF-Methode ToListAsync. Aber nichts passierte - keine Ausnahme, kein timeout läuft.
Dies ist mein 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();
}
Den ersten sync-Aufruf von ToList-Methode return Ergebnis sofort. Die zweite async call of ToListAsync läuft noch kein Ergebnis noch die Ausnahme.
Irgendwelche Vorschläge?
InformationsquelleAutor Martin Majoroš | 2014-02-25
Du musst angemeldet sein, um einen Kommentar abzugeben.
Vermute ich, dass weiter oben auf Ihren Anruf-Stapel, Ihr code ruft
Task.Wait
oderTask<T>.Result
. Wenn Sie dies tun, auf den UI-thread oder von einem ASP.NET Anforderung Kontext, Ihr code wird deadlock, wie erkläre ich auf meinem blog.Um es zu beheben, verwenden Sie
await
stattTask.Wait
oderTask<T>.Result
.InformationsquelleAutor Stephen Cleary