[英]Empty DbProviderFactories in .net-core application and mashine.config(s)
I'm noticed the code 我注意到了代码
`DataTable table = DbProviderFactories.GetFactoryClasses();`
works different in applications targeted as .NET Framework 4.x and .NET Core 2.x. 在以.NET Framework 4.x和.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.
对于前一个应用程序,我收到包含4个项目的提供程序列表,对于后一个应用程序,该列表为空。
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). 我已经读过类似的问题,并发现提供程序列表存储在
mashine.config
文件中(我有控制台应用程序,所以我没有web.config
,只有一个app.config
文件几乎是空的)。 So I assume my problem is linked with mashine.config
file(s). 因此,我假设我的问题与
mashine.config
文件链接。
I have found 6 mashine.config
files on my desktop. 我在桌面上找到6个
mashine.config
文件。
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
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。 \\ 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 文件夹v2.0.50727和winsxs中的文件具有“完整”部分
<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: 但是v4.0.30319版中的文件为空:
<system.data>
<DbProviderFactories/>
</system.data>
I can see it on two PCs, so I don't think my Windows or NET installations are corrupted. 我可以在两台PC上看到它,因此我认为Windows或NET安装没有损坏。
So now here are my questions: 所以现在这是我的问题:
DbProviderFactories
list from mashine.config
file located in v4.0.30319 folder? DbProviderFactories
从列表mashine.config
位于v4.0.30319文件夹中的文件? Thanks. 谢谢。
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. EF Core与之前使用的EF5 / 6略有不同。 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). 使用EF Core,我们可以在VS Package Manager控制台中基于现有数据库构建模型(好的,我们也可以使用dotnet CLI,但是对我来说,使用前一个更容易)。 And we need to add a required DB provider via NuGet Manager.
并且我们需要通过NuGet Manager添加所需的数据库提供程序。
I fond the pretty tutorial here: http://www.entityframeworktutorial.net/efcore/entity-framework-core.aspx . 我在这里喜欢漂亮的教程: 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). 另外, 这里有一篇很好的文章,说明有人可以实现
DbProviderFactory
动态加载(这是我的问题的起点)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.