2013-12-11 50 views
5

我有一个使用Visual Studio 2013和ADO.NET实体数据模型(EF6)创建的新项目。EF6不支持上下文类型'System.Data.Entity.Core.Objects.ObjectContext'

现在我必须使用一些动态数据功能(如访问元表对象),所以我添加以下代码:

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

,但我得到这个错误:

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

注该项目的参考更新为EF6(system.data.entity.core)

回答

8

EF6的Dynamic Data Provider和EntityDataSource控件的新预览版已经发布。请检查一下,它为我工作。

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

要注册供应商:

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

是的。

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.

参考文献:

+0

我没有老参考,请记下错误报告正确的命名空间:System.Data.Entity.Core.Objects.ObjectContext .. – gidanmx2

+0

是的,我明白了!我只是忽略了!道歉! –

4

DynamicData做不支持的EntityFramework 6却又如此降级到EF 5 '解决' 的问题。

+0

您是如何特意“降级到EF5”的? –

+1

Uninstall-Package EntityFramework -Force,Install-Package EntityFramework -Version 5.0.0请参阅:http://stackoverflow.com/questions/10206090/how-to-install-an-older-version-of-package-via-nuget – gidanmx2

+0

目前支持:http://stackoverflow.com/a/22016040/842935 – danihp

相关问题