Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF 6 System.Data.Objects.ObjectContext Error

EF 6 does not have System.Data.Objects.ObjectContext. EF 6 has moved some types, including ObjectContext, from System.Data.Entity.dll into EntityFramework.dll, and changed their namespaces. The fact that you get this error suggests you haven't attempted to recompile your application, you've simply replaced EntityFramework.dll and hoped for the best. That won't work. You need to update your code to work with EF 6: you need to remove your references to System.Data.Entity.dll, and update your code to refer to the new types.

It just might be possible for the reference to the IObjectContextAdapter.ObjectContext property to be in some library you're using, but most likely it'll be in your own code. The error message (in the part you didn't include in your question) should tell you where it is coming from.


For me updating these below worked:
using System.Data.Objects; --> using System.Data.Entity.Core.Objects;

using System.Data.Objects.DataClasses; --> using System.Data.Entity.Core.Objects.DataClasses;


I'm also using EF 6.

I managed to solve the problem uninstalling the package Microsoft.AspNet.Providers.Core v. 1.2. I'm using version 1.1 instead. If you're like me and is using LocaDb, you'll have to uninstall the LocaDb package because it depends on that package. Of course you'll have to reinstall LocaDb again...

You can grab v. 1.1 using the NuGet Package Manager Console inside Visual Studio:

Install-Package Microsoft.AspNet.Providers.Core -Version 1.1

There's a Microsoft Connect bug filled regarding this issue:

Microsoft.AspNet.Providers.Core incompatible with EF6


The new 2.0 version of the providers (http://www.nuget.org/packages/Microsoft.AspNet.Providers.Core/) are EF6 compatible (they'll actually only work with EF6).


I managed to resolve this by removing the AspNet Providers I had installed through Nuget, which was marked as deprecated. Doing this also uninstalled Entity Framework.

I then installed the new AspNet Universal Providers, followed by Entity Framework 6, and all my problems were fixed.