简体   繁体   中英

Using 2 different versions of EF in the same Project

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 (eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM