Missing QueryableExtensions in EF 6

2019-06-22 19:45发布

I can't call the new QueryableExtensions (ToListAsync, ForEachAsync,...) provided with EntityFramework 6. But i can call others (Include, Intersect).

I've a reference to System.Data.Entity. So apparently, i've an older version of System.Data.Entity, with the latest version of EntityFramework. Is it possible?

My code does not compile and I cannot see the ForEachAsync method in the object browser.

I'm working with Visual Studio 2013, .Net 4.5, EntityFramework 6.1.3, Wpf.

Edit

Entity framework is installed : EF installed

I've tried to Uninstall then Reinstall package many times, with a restart of visual studio. Still not working

Edit

In another project (referenced by this one), I can see the IQueryableExtensions needed in the object browser. If I add this project to my solution (before it was only a reference), the IQueryableExtensions needed are missing in the object browser.

3条回答
爷、活的狠高调
2楼-- · 2019-06-22 20:36

One of your projects is probably targeting an older version of the .net framework.

I had this issue when a project was targeting .Net v4.0, update it to 4.5 or newer. I also ran the command that others recommended after this.

update-package -reinstall EntityFramework 

You can see what version of .Net is is targeting when you run the update-package command in the package console. For example output from my project when it was targeting 4.0

PM> Update-Package –reinstall EntityFramework
Attempting to gather dependencies information for multiple packages with respect to project '[My project]', targeting '.NETFramework,Version=v4.0'

and then with v4.5.2:

PM> Update-Package –reinstall EntityFramework
Attempting to gather dependencies information for multiple packages with respect to project '[My Project]', targeting '.NETFramework,Version=v4.5.2'

You update your .net version by:

right clicking on the project in the solution explorer, 
choosing "Properties"
on the Application Tab (default) from the DropDown list labeled "Target Framework" select 4.5 (or greater - I chose 4.5.2)

There is a chance you don't need to reinstall the package, however I reinstalled before checking if it worked.

查看更多
爷的心禁止访问
3楼-- · 2019-06-22 20:39

Probably you have installed EntityFramework package when your project was targeting .NET v4.0. Even though you have migrated your project to .NET v4.5, the QueryableExtensions class still does not contain the async methods because the package was installed before migration.

Just reinstall the Entity Framework package.

查看更多
干净又极端
4楼-- · 2019-06-22 20:43

You need to reference the EntityFramework.dll. Remove the reference to System.Data.Entity.dll manually (if it is present).

Take a look at QueryableExtensions on MSDN

With Nuget it should be simple, cause this will add the dependencies fro you

install-package EntityFramework

or use the update command

Update-Package –reinstall EntityFramework

This will install the latest version of Entity Framework (6.1.3)

查看更多
登录 后发表回答