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

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

问题描述

在我当前的项目中,我有两个项目引用,它们是 DataContexts.一种用于访问 Oracle Db,并且使用 EF 4.2.另一个是访问 SQL Server 并使用 EF 6.0.

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.

这是我得到的:

  • 我参考了 EF 6.0.
  • 在预构建命令中,我将两个 dll 复制到单独的文件夹中

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

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.0EntityFramework.dll" />
        <codeBase version="4.2.0.0" href="ef4.2EntityFramework.dll" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

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

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'.

有什么提示吗?

推荐答案

与所引用问题/答案的不同之处在于,在另一种情况下,有两个 DLL 使用不同版本的依赖项.就您而言,您正尝试在同一个项目中使用两个不同版本的依赖项.

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.

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

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.

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

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天全站免登陆