Using 2 different versions of EF in the same Project

蓝咒 提交于 2019-12-02 11:48:47

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/27925286/using-2-different-versions-of-ef-in-the-same-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!