I'm trying a call a .Net 4.7 data access library (which uses Entity Framework 6) from a new Asp Net Core 2.0 Web Application.
The issue is that EF6 can't seem to get hold of a DbProviderFactory. My working theory is that this is something that should be provided in the app/web.config of the calling program. The error that I'me getting is:
System.TypeLoadException: 'Could not load type 'System.Data.Common.DbProviderFactories' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.'
In an effort to circumvent this issue, I created a DbConfiguration class:
public class MyDbConfiguration : DbConfiguration
{
public MyDbConfiguration()
{
SetProviderFactory("System.Data.SqlClient", System.Data.SqlClient.SqlClientFactory.Instance);
SetProviderServices("System.Data.SqlClient", SqlProviderServices.Instance);
}
}
[DbConfigurationType(typeof(MyDbConfiguration))]
public class MyDbContext : DbContext, IMyDbContext
{
public MyDbContext(string connectionString)
: base(connectionString)
{
}
A breakpoint shows that it executes the MyDbConfiguration correctly, but still throws the error. I've installed the System.Data.SqlClient and System.Data.Common packages on the .Net Core web app.
I haven't found anything that explicitly says what I'm trying to do (in general) is not possible, so I'm working on the assumption that there's something wrong with my DBConfiguration implementation. Please could someone point me in the right direction?