I have a ASP.NET MVC4 that talks to a database via EntityFramework 6.0. The DbContext was created using the EDMX designer with database-first. The application is aiming at .NET Framework 4.0.
In order to be able to use the new async methods like .FirstOrDefaultAsync() I tried to upgrade EF to the current stable version 6.1.3.
So I ran Update-Package EntityFramework in the Nuget console. It took some seconds, no error messages appeared and the installation ended with:
Successfully installed 'EntityFramework 6.1.3' to MyProject
After that, I ran Build --> Clean Solution and then rebuild everything. Next, I made sure that my controller contains these using statements (besides others):
using System.Data.Entity;
using System.Threading.Tasks;
However, I still can't use any async methods, they're simply not found. Here's an example:
using (MyEntities db = new MyEntities())
{
var dp = await db.DataPoints.FirstOrDefaultAsync(x => x.Id == DataPointId);
}
FirstOrDefaultAsync is marked as faulty by Intellisense, when trying to build anyway I get this error:
'DbSet<DataPoint>' does not contain a definition for 'FirstOrDefaultAsync' and no extension method 'FirstOrDefaultAsync' accepting a first argument of type 'DbSet<DataPoint>' could be found (are you missing a using directive or an assembly reference?)
What can I do to resolve this issue? Which actions need to be taken? Thanks for your help!
You need to uninstall all your NuGet packages, change your target .NET version to 4.5 or higher, and then reinstall all your NuGet packages.
Then open web.config and then set the targetFramework attribute of the httpRuntime element to the version that you're targeting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With