实体DataSource不能与Entity Framework 6升级 [英] Entity DataSource not working with Entity Framework 6 Upgrade

查看:118
本文介绍了实体DataSource不能与Entity Framework 6升级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将我们的Webforms应用程序从EF 4.4升级到EF6,并且我使用Entity Datasource控件编制了很多编译时错误。一般来说,当尝试访问上下文对象时,我会发生所有出现这些错误:

  e.Context 

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



显示的错误信息是:


1)Module System.Data.Entity。应该引用version =4.0.0.0



2)不能将System.Data.Objects.ObjectContext类型的表达式表示为
type ObjectContext(显式类型之后转载给System.Data.Entity.Core.Objects.ObjectContext)


有人可以帮助解决这个问题吗?

解决方案

从EF 5升级到EF 6时,我刚刚完成了这个练习,我也有同样的错误。



这是我必须做的。

  Install-Package Microsoft.AspNet.EntityDataSource 

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

 < pages> 
< controls>
< add tagPrefix =efassembly =Microsoft.AspNet.EntityDataSourcenamespace =Microsoft.AspNet.EntityDataSource/>
< / controls>
< / pages>

下一步是替换现有的< asp:EntityDataSource /> / code>控制到您的aspx页面中的< ef:EntityDataSource />



一步是进入你的代码,并更新EntityDataSourceContextCreatingEventArgs或任何其他类型的EFContext标签的引用。



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

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

这一切都有效,我没有在程序集中引用System.Data.Entity。


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

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

The error information which is showing up is:

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

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?

解决方案

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

Here is what I had to do.

Install-Package Microsoft.AspNet.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>

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

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

From

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

To

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

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

这篇关于实体DataSource不能与Entity Framework 6升级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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