实体数据源无法与实体框架 6 升级一起使用 [英] Entity DataSource not working with Entity Framework 6 Upgrade

查看:21
本文介绍了实体数据源无法与实体框架 6 升级一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将我们的 Webforms 应用程序从 EF 4.4 升级到了 EF6,但我在使用 Entity Datasource 控件时遇到了很多编译时构建错误.通常,在尝试访问上下文对象时,我在所有出现的情况下都会收到这些错误:

I recently upgraded our Webforms application from EF 4.4 to EF6 and I got so many compile time build errors with the Entity Datasource controls. Generally I am getting these error in all occurrences when trying to access the context object :

e.Context

我遵循了与以下内容相同的演练:http://entityframework.codeplex.com/wikipage?title=Updating%20Applications%20to%20use%20EF6

I have followed the same walkthrough as given in : http://entityframework.codeplex.com/wikipage?title=Updating%20Applications%20to%20use%20EF6

出现的错误信息是:

1) 模块 System.Data.Entity.应该引用version="4.0.0.0"

1) Module System.Data.Entity. version="4.0.0.0" should be referenced

2) 不能将 System.Data.Objects.ObjectContext 类型的大小写表达式转换为type ObjectContext(显式类型转换为 System.Data.Entity.Core.Objects.ObjectContext 之后)

2) Cannot case expression of type System.Data.Objects.ObjectContext to type ObjectContext (After explicitly type casting to System.Data.Entity.Core.Objects.ObjectContext)

谁能帮忙解决这个问题?

Can anybody help to fix this?

推荐答案

我刚刚从 EF 5 升级到 EF 6 时进行了这个练习,我遇到了同样的错误.

I just went through this exercise when upgrading to EF 6 from EF 5 and I had the same errors.

这是我必须做的.

Install-Package Microsoft.AspNet.EntityDataSource

它会在页面下的 web.config 中注册一个新的 EntityDataSource 控件:

It would register a new EntityDataSource Control in the web.config under pages:

<pages>
  <controls>
    <add tagPrefix="ef" assembly="Microsoft.AspNet.EntityDataSource" namespace="Microsoft.AspNet.EntityDataSource" />
  </controls>
</pages>

下一步是将现有 <asp:EntityDataSource/> 控件替换为您的 aspx 页面中的 <ef:EntityDataSource/>.

Next step is to replace existing <asp:EntityDataSource /> controls to <ef:EntityDataSource /> in your aspx pages.

最后一步是进入您的代码并更新 EntityDataSourceContextCreatingEventArgs 或任何其他类型的 EFContext 标记的引用.

Final step is to go in your code behind and update references for EntityDataSourceContextCreatingEventArgs or any other type of EFContext tags.

来自

protected void OnContextCreating(object sender, EntityDataSourceContextCreatingEventArgs e){... } 

protected void OnContextCreating(object sender, Microsoft.AspNet.EntityDataSource.EntityDataSourceContextCreatingEventArgs e){... } 

一切正常,我不必在程序集中引用 System.Data.Entity.

It all worked and I didn't have to reference System.Data.Entity in the assembly.

这篇关于实体数据源无法与实体框架 6 升级一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆