EF6 'DbConfigurationClass' was set but this type was not discovered - multiple DbContexts and DbConfigurations
Easiest solution seems to have been to move to config-file based configuration, as detailed here.
The reason I couldn't get this to work the first time is because I had a different version of EF listed in one of the various config files and didn't catch it.
I did try using a single DbConfiguration class in a common library and was able to get it to work this time (with no real fiddling, I must have just done something terribly wrong the first time) but I think that the config-file based configuration is the better solution.
Putting configuration information in a config file, how novel!
According to Microsoft you can solve two DbContexts with DbConfiguration
like this:
XML:
<entityFramework codeConfigurationType="MyNamespace.MyDbConfiguration, MyAssembly">
...Your EF config...
</entityFramework>
Code:
[DbConfigurationType(typeof(MyDbConfiguration))]
public class MyContextContext : DbContext
{
}
[DbConfigurationType("MyNamespace.MyDbConfiguration, MyAssembly")]
public class MyContextContext : DbContext
{
}
https://docs.microsoft.com/en-us/ef/ef6/fundamentals/configuring/code-based
I did not solve multiple DbConfiguration
however. My solution was sharing the same DbConfiguration
for both DbContexts like this:
public class DbContextConfiguration : DbConfiguration
{
public DbContextConfiguration()
{
var providerInstance = SqlProviderServices.Instance;
SqlProviderServices.TruncateDecimalsToScale = false;
this.SetProviderServices(SqlProviderServices.ProviderInvariantName, SqlProviderServices.Instance);
}
}
[DbConfigurationType(typeof(DbContextConfiguration))]
public class DbContext1 : DbContext
{
}
[DbConfigurationType(typeof(DbContextConfiguration))]
public class DbContext2 : DbContext
{
}