在同一个项目中使用2种不同版本的EF [英] Using 2 different versions of EF in the same Project

查看:260
本文介绍了在同一个项目中使用2种不同版本的EF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我目前的项目中,我有两个DataContexts项目引用。一个是访问Oracle Db并正在使用EF 4.2。另一个是访问SQL Server并使用EF 6.0。



我已经阅读了这个解决方案,但我不能让它上班。



这是我得到的:




  • 我引用了EF 6.0。 li>
  • 在一个预构建命令中,我复制了两个dll在单独的文件夹



在我的Appconfig中,我添加这个:

 < runtime> 
< assemblyBinding xmlns =urn:schemas-microsoft-com:asm.v1>
< dependentAssembly>
< assemblyIdentity name =EntityFrameworkpublicKeyToken =b77a5c561934e089/>
< codeBase version =6.0.0.0href =ef6.0\EntityFramework.dll/>
< codeBase version =4.2.0.0href =ef4.2\EntityFramework.dll/>
< / dependentAssembly>
< / assemblyBinding>
< / runtime>

我还在得到:类型System.Data.Objects.ObjectContext在程序集中定义那是没有引用的。您必须添加对程序集System.Data.Entity,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089的引用。



任何提示?

解决方案

答案是,在另一种情况下,有两个DLL使用不同版本的依赖关系。在您的情况下,您尝试在同一个项目中使用两个不同版本的依赖关系。



您可以尝试将您的特定于版本的代码两个DLL(例如OracleDataAccess和SqlDataAccess)。在每个项目中,您可以参考特定版本的EF。从您的主要项目中,您可以引用两个... DataAccess项目,如果一切顺利,则dependentAssembly配置文件条目应在运行时解决两个EF DLL的版本冲突。



注意:您可能还需要调整EF依赖关系如何复制到构建目录以匹配配置文件中的href。


In my current Project i have two Project References that are DataContexts. One is for accessing an Oracle Db and is using EF 4.2. The other is accessing a SQL Server and uses EF 6.0.

I already read this solution, but i can't get it to work.

Here is what i got:

  • I referenced EF 6.0.
  • In a Pre-build command i xcopied both dlls in seperate folders

In my Appconfig i added this:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
        <codeBase version="6.0.0.0" href="ef6.0\EntityFramework.dll" />
        <codeBase version="4.2.0.0" href="ef4.2\EntityFramework.dll" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

I am still getting: The type 'System.Data.Objects.ObjectContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Any hints?

解决方案

The difference to the referenced question/answer is that in the other case there are two DLLs that use different versions of a dependency. In your case, you are trying to use two different versions of a dependency within the same project.

You may try to factor out (wrap) your version-specific code into two DLLs (e.g. OracleDataAccess and SqlDataAccess). In each of those projects you can now reference the specific version of EF. From your main project you then reference the two ...DataAccess projects, and if everything goes well, the dependentAssembly config file entry should resolve the version conflict for the two EF DLLs at runtime.

Note: You might also need to tweak how the EF dependencies are copied to the build directory to match the hrefs in the config file.

这篇关于在同一个项目中使用2种不同版本的EF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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