Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing QueryableExtensions in EF 6

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.

like image 343
ZwoRmi Avatar asked Sep 02 '15 06:09

ZwoRmi


People also ask

What does FirstOrDefaultAsync return?

FirstOrDefaultAsync<TSource>(IQueryable<TSource>, CancellationToken) Asynchronously returns the first element of a sequence, or a default value if the sequence contains no elements.

What is ToListAsync?

ToListAsync(IQueryable) Creates a List<T> from an IQueryable by enumerating it asynchronously. ToListAsync(IQueryable, CancellationToken) Creates a List<T> from an IQueryable by enumerating it asynchronously.

What does IQueryable include do?

Include(IQueryable, String)Specifies the related objects to include in the query results.


2 Answers

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.

like image 165
Peter Avram Avatar answered Oct 21 '22 11:10

Peter Avram


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)

like image 29
Jehof Avatar answered Oct 21 '22 11:10

Jehof