简体   繁体   English

在VS2012中使用动态数据实体网站时出错

[英]Error in using Dynamic Data Entities Web Site in VS2012

I decided to use Dynamic Data Entities Web Site in VS2012. 我决定在VS2012中使用动态数据实体网站。

So, I created this Web Site, then added App_Code directory and added a new edmx to it and named it myDB.edmx . 因此,我创建了这个Web站点,然后添加了App_Code目录并edmx添加了一个新的edmx其命名为myDB.edmx After that I uncommented the code line in Global.asax which registers the entity context : 之后,我取消注释了Global.asax中注册实体上下文的代码行:

DefaultModel.RegisterContext(typeof(myDBEntities), new ContextConfiguration() { ScaffoldAllTables = true });

But when I run the website this error occurs : 但是当我运行网站时,会发生以下错误:

The context type 'myDBEntities' is not supported.

how can I fix it? 我该怎么解决?

ps: You now there are some differences between using L2S by Dynamic Data L2S Web Site and using Entity Framework by Dynamic Data Entities Web Site . ps:您现在使用Dynamic Data L2S Web SiteDynamic Data Entities Web Site使用实体框架之间存在一些差异。

我仍在寻找原因,但是现在唯一的选择是在VS2010中创建项目然后将项目迁移到VS2012然后我在运行应用程序时没有任何问题

This problem happens because in Visual Studio 2012 you get DbContext (instead of ObjectContext as in Visual Studio 2010) code generated by default for all new models created with the EF Designer. 出现此问题的原因是,在Visual Studio 2012中,您将获得默认情况下为使用EF Designer创建的所有新模型生成的DbContext (而不是Visual Studio 2010中的ObjectContext )代码。 In order to solve one you need to revert back to ObjectContext code generation. 为了解决这个问题,您需要恢复到ObjectContext代码生成。

For more information see Reverting to ObjectContext in EF Designer . 有关更多信息,请参阅EF Designer中的还原为ObjectContext

  1. Delete the TT files from the model 从模型中删除TT文件

  2. Change the "Code Generation Stategy" to "Default" 将“代码生成状态”更改为“默认”

Within the Global.asax file, uncomment the other RegisterContext line instead. 在Global.asax文件中,取消注释其他RegisterContext行。

 DefaultModel.RegisterContext( _
           New System.Func(Of Object)(Function() DirectCast(New [Your edmx](), IObjectContextAdapter).ObjectContext), _
           New ContextConfiguration() With {.ScaffoldAllTables = True} _
         )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM