0
votes

I'm noticed the code

`DataTable table = DbProviderFactories.GetFactoryClasses();` 

works different in applications targeted as .NET Framework 4.x and .NET Core 2.x. For the former application I receive the providers list with 4 items and for the latter one the list is empty.

I have read about similar issues and figured out the providers list is stored in mashine.config file (I have console applications, so I haven't web.config and have only one app.config file which is almost empty). So I assume my problem is linked with mashine.config file(s).

I have found 6 mashine.config files on my desktop.

c:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config c:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG\machine.config c:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config c:\Windows\winsxs\amd64_netfx-machine_config_ocm_b03f5f7f11d50a3a_6.1.7601.17514_none_81fa0191bdd08961\machine.config c:\Windows\winsxs\x86_netfx-machine_config_ocm_b03f5f7f11d50a3a_6.1.7601.17514_none_c9a73868d24cb267\machine.config

Files from folders v2.0.50727 and winsxs have the "full" section

   <system.data>
        <DbProviderFactories>
           <add name="Odbc Data Provider"         invariant="System.Data.Odbc"         description=".Net Framework Data Provider for Odbc"      type="System.Data.Odbc.OdbcFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
           <add name="OleDb Data Provider"        invariant="System.Data.OleDb"        description=".Net Framework Data Provider for OleDb"     type="System.Data.OleDb.OleDbFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
           <add name="OracleClient Data Provider" invariant="System.Data.OracleClient" description=".Net Framework Data Provider for Oracle"    type="System.Data.OracleClient.OracleClientFactory, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
           <add name="SqlClient Data Provider"    invariant="System.Data.SqlClient"    description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        </DbProviderFactories>
    </system.data>

but files from v4.0.30319 have the empty one:

<system.data>
    <DbProviderFactories/>
</system.data>

I can see it on two PCs, so I don't think my Windows or NET installations are corrupted.

So now here are my questions:

  1. Am I right in .NET Core 2.x application gets DbProviderFactories list from mashine.config file located in v4.0.30319 folder?
  2. Why this list is empty? I mean, what software is responsible for its filling? Do I need to install/add/restore something?
  3. Is it safe to add providers list in this file manually (just to copy from "full-list" file)?

Thanks.

1
.NET Core is light framework that not use GAC and therefore you can install globally DbProviders. You should install them for every your application. Or use full Framework.Grzesiek Danowski
@GrzesiekDanowski, excuse me, but I don't understand how to install DbProviders for the application. I have references to Microsoft.EntityFrameworkCore and Microsoft.EntityFrameworkCore.SqlServer packages in my .csproj file, but it isn't to be enough...Miamy
@GrzesiekDanowski, thank you! It seems this guy knows what to do with my problem :)Miamy

1 Answers

0
votes

I decide to post the answer because this topic really was not clear to me and I hope I can help anyone to avoid my mistakes.

EF Core is slightly different from EF5/6 I was used before. There is no visual designer for database<->model operations here. There is no early-known DB providers too.

With EF Core we can build a model based on existing database in VS Package Manager Console (ok, we can use dotnet CLI too, but as for me it's easier to use the former one). And we need to add a required DB provider via NuGet Manager.

I fond the pretty tutorial here: http://www.entityframeworktutorial.net/efcore/entity-framework-core.aspx.

Also, here there is a good article how someone can implement DbProviderFactory dynamic loading (it's was a starting point of my question).