I have recently updated EntityFramework in my WebAPI project from v5 to v6. Unfortunately it seems like somewhere, somehow, there is a reference that exists in some config s
I was running into the exact same problem with having a Virtual Directory running EF6 and the root directory running EF5. Took me a few hours but I found a fix:
In the virtual directory Web.config, remove/comment out the configSection for EF6 (this stops you from duplicating the entityFramework section), add an assembly binding redirect (so it maps the root's EF5 configSection to EF6, but only in the Virtual Directory) and finally remove all the configuration so it doesn't try to look for a configSection for EF6 in the Virtual Directory. My new Web.config file looks like this:
... rest of configuration ...
Next I added a DbConfiguration class to the assembly that contains the DbContext (this basically enables the EF6 code first configuration). For example:
public class MyConfiguration : DbConfiguration
{
public MyConfiguration()
{
SetDefaultConnectionFactory(new SqlConnectionFactory("Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True"));
}
}
And that was it, now I can have both EF versions working along each other. The tricky part for me was figuring out how to do the AssemblyBinding from EF5 to EF6 redirect. Also notice that I didn't change anything in the root Web.config.
Hopefully this helps someone out there having the same issue.