EF6 Type of context 'System.Data.Entity.Core.Objects.ObjectContext' is not supported

12,859

Solution 1

A new preview of Dynamic Data Provider and EntityDataSource control for EF6 has been released. Please check this out, it worked for me.

http://blogs.msdn.com/b/webdev/archive/2014/01/30/announcing-preview-of-dynamic-data-provider-and-entitydatasource-control-for-entity-framework-6.aspx#

To register the provider:

MetaModel model = new MetaModel();
model.RegisterContext(
    new Microsoft.AspNet.DynamicData.ModelProviders.EFDataModelProvider(
       () => new KiwiJuiceEntities()
    ),
    new ContextConfiguration() { ScaffoldAllTables = true }
);     

Solution 2

DynamicData do no support EntityFramework 6 yet so downgrading to EF 5 'solve' the problem.

Solution 3

Yes.

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.

References:

Share:
12,859

Related videos on Youtube

gidanmx2
Author by

gidanmx2

Updated on September 16, 2022

Comments

  • gidanmx2
    gidanmx2 over 1 year

    I have a new project created using Visual Studio 2013 with an ADO.NET Entity Data Model (EF6).

    Now I have to use some Dynamic Data function (like access to MetaTable object), so I add this code:

    MetaModel model = new MetaModel();
            model.RegisterContext(() =>
            {
                return ((System.Data.Entity.Infrastructure.IObjectContextAdapter)new KiwiJuiceEntities()).ObjectContext;
            }, new ContextConfiguration() { ScaffoldAllTables = true });
    

    but I've got this error:

    Type of context 'System.Data.Entity.Core.Objects.ObjectContext' is not supported
    

    Note that the project have the reference updated to EF6 (system.data.entity.core)

  • gidanmx2
    gidanmx2 over 10 years
    I don't have the old reference, note the error report the correct namespace: System.Data.Entity.Core.Objects.ObjectContext...
  • Siva Krishna Macha
    Siva Krishna Macha over 10 years
    Yes, I see! I just overlooked! Apologies!
  • Antoine Meltzheim
    Antoine Meltzheim over 10 years
    How did you specifically "downgrade to EF5" ?
  • gidanmx2
    gidanmx2 over 10 years
    Uninstall-Package EntityFramework -Force, Install-Package EntityFramework -Version 5.0.0 see: stackoverflow.com/questions/10206090/…