小编sch*_*ien的帖子

EntityFramework ToListAsync()不起作用

我尝试调用EF方法ToListAsync.但没有任何事情发生 - 没有例外,没有超时只是运行.

这是我的代码.

        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();
    }
Run Code Online (Sandbox Code Playgroud)

ToList方法的第一次同步调用立即返回结果.ToListAsync的第二次异步调用仍在运行,没有结果也没有异常.

有什么建议?

.net c# async-await entity-framework-6

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

.net ×1

async-await ×1

c# ×1

entity-framework-6 ×1