Missing QueryableExtensions in EF 6

泄露秘密 提交于 2019-12-23 11:22:30

问题


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 :

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.


回答1:


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.




回答2:


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)




回答3:


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.



来源:https://stackoverflow.com/questions/32346016/missing-queryableextensions-in-ef-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!