简体   繁体   English

EntityFramework ToListAsync()不起作用

[英]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.WaitTask<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.WaitTask<T>.Result

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 EntityFramework Core 可空谓词 ToListAsync - EntityFramework Core nullable predicate ToListAsync .NET 6:context.db.Where().Orderby().ToListAsync() 不起作用 - .NET 6 : context.db.Where().Orderby().ToListAsync() does not work ToListAsync()根本没有完成 - ToListAsync() does not complete at all 为什么实体框架在类库中不起作用 - Why entityframework does not work in class libraries EF5 IQueryable 不包含 ToListAsync 的定义 - EF5 IQueryable does not contain a definition for ToListAsync EntityFramework代码优先的DateTime列不能按预期工作 - DateTime column in EntityFramework code-first does not work as expected 异步Web请求,EntityFramework和DI,它是如何工作的? - Asynchronous Web Request, EntityFramework, and DI, how does it work? 向EntityFramework 6添加视图不起作用? - Add view to EntityFramework 6 not work? 实体框架核心不包含 ToListAsync 时,但包含 FirstOrDefaultAsync - Entity framework core does not include when ToListAsync, but does with FirstOrDefaultAsync 方法获取列表异步? &#39;清单 <ListDefinition> &#39;不包含&#39;ToListAsync&#39;的定义 - Method for getting a list async? 'List<ListDefinition>' does not contain a definition for 'ToListAsync'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM