Search code examples
c#.netasync-awaitentity-framework-6

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


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!


Solution

  • 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.