Can not use .ToListAsync() extension method (.net 4.7)

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


Im am trying to use extension method .ToListAsync() but for some reason this extension method not available for me.

My set up as follows:

  • Web Project (.Net 4.7) here i did include using System.Data.Entity;
  • DataAcess Project (.Net 4.7) here I interlude Entity Frame Work v6.2

My Web Project does reference my DataAccess project.

Im not sure where i went wrong. Can somebody please advise?

Thank you!

1/21/2018 11:31:34 PM

Accepted Answer

The ToListAsync method is part of the QueryableExtensions class which is in the System.Data.Entity namespace and part of the EntityFramework.dll library. This means that you need import the namespace (i.e. using System.Data.Entity;) as well as reference EntityFramework.dll.

Note that in classic .Net Framework projects, references are not transitive. In other words, if you want to use classes from a library, you must reference it in every project. This has changed in .Net Core though.

1/21/2018 11:42:38 PM

Popular Answer

While the .ToListAsync() method is made available by referencing the EntityFramework.dll and using System.Data.Entity;, it is only available on types that implement the IQueryable interface.

An example of it being used:

private async Task<List<Book>> GetAllBooksAsync() {

    var books = new List<Book>();
    var query = from item in books select item;
    return await query.AsQueryable().ToListAsync();

As a note, if you can't see the ToListAsync() method, you may be missing the using System.Data.Entity; in your class.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow