Domanda

Provo a chiamare il metodo EF Tolistasync.Ma nulla è successo - nessuna eccezione, nessun timeout solo in esecuzione.

Questo è il mio codice.

        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();
    }
.

La prima chiamata di sincronizzazione del metodo del tolant è immediatamente il risultato del rendimento.La seconda chiamata di Async di Tolistasync ancora in esecuzione senza risultato né eccezione.

Qualche suggerimento?

È stato utile?

Soluzione

Sospetto che ulteriormente stia aggiornando il tuo stack di chiamata, il tuo codice chiamano Task.Wait o Task<T>.Result.Se lo fai sulla filettatura dell'interfaccia utente o da un contesto di richiesta ASP.NET, il tuoIl codice sarà il punto morto , mentre spiego il mio blog.

Per fissarlo, utilizzare await anziché Task.Wait o Task<T>.Result.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top