I am implementing a model using EF 6.1.3 and the .NET Framework 4.6.1. This model is used by the ASPNET application and the ASPNET CORE application, therefore it uses System.Data.Entity and is located in a separate assembly mymodel.dll.
This is a model
using System.Data.Entity; public partial class MyDbContext : DbContext { public virtual DbSet<Athlete> Athletes{ get; set; } } public partial class Athlete { public Athlete() { }
I am developing an MVC application that is implemented in the aspnet core with the .NET Framework 4.6. It refers to EF 6.1.3 so that the model can be used.
public class MyViewModel { public IList<Athlete> ItalianAthletes{ get; set; } } using Microsoft.EntityFrameworkCore;
... and works as expected.
Now change the Index method to async
public async Task<IActionResult> Index() { MyViewModel myvm = new MyViewModel(); var result = _context.Athletes.Where(a=>a.Country=="Italy").ToListAsync(); await result;
InvalidOperationException: The source IQueryable does not implement IAsyncEnumerable. Only sources that implement IAsyncEnumerable can be used for asynchronous Entity Framework operations.
Removing the Where () clause the problem persists, therefore the problem is related to ToListAsync ();
var result = _context.Users.ToListAsync();
After carefully reading the exception text, I understand that "IQueryable generated by ToList () does not implement IAsyncEnumerable", but this does not make sense to me because all this behavior is internal to ToListAsync ();
Can someone help me better understand what is happening here under the hood? and what can I do to make ToListAsync () work as expected?
in advance for any comment
c # asynchronous entity-framework
Roberto vanoli
source share