我在 ASP.NET MVC Core 和 Entity Framework 中有以下代码,当我执行 ToListAsync
时出现以下错误。
Additional information: The source IQueryable doesn't implement IDbAsyncEnumerable. Only sources that implement IDbAsyncEnumerable can be used for Entity Framework asynchronous operations. For more details see http://go.microsoft.com/fwlink/?LinkId=287068.
这是我的代码:
var states = mDbContext.State.ToListAsync();
var countries = mDbContext.Country.ToListAsync();
mMemoryCache.Set(Countries, await countries,
new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.MaxValue));
mMemoryCache.Set(States, await states,
new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.MaxValue));
我的上下文类从 DbContext
扩展而来,我使用的是 EF 6。
public virtual DbSet<Country> Country { get; set; }
public virtual DbSet<State> State { get; set; }
知道为什么我无法执行 ToListAsync()
即使我已经安装了所有东西吗?
最佳答案
ToListAsync()
在 System.Data.Entity
和 Microsoft.EntityFrameworkCore
中定义。如果同时导入两者,它将默认为生成上述错误的 System.Data.Entity 中的定义。删除 System.Data.Entity
并添加 try adding using Microsoft.EntityFrameworkCore
;
关于c# - ASP.NET MVC Core 和 Entity Framework 中的 ToListAsync 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41305461/