我需要让DbProviderFactories.GetFactory()返回Sqlite的提供程序。但是,我已经通过NuGet向我的项目添加了Sqlite,并且希望避免将它放在GAC中并更新machine.config。Sqlite的优点之一是它没有任何配置。
但是,我有许多库可以从GetFactory()中提取连接器。
有办法这样做吗?
谢谢-戴夫
发布于 2018-08-27 13:21:01
您只需将一个app.config文件添加到您的项目中,就可以添加要添加的不变量。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite"></remove>
<add name="ADO.NET Provider for SQLite"
invariant="System.Data.SQLite"
description="ADO.NET Provider for SQLite "
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite">
</add>
</DbProviderFactories>
</system.data>
</configuration>type属性包含提供程序工厂的命名空间和提供程序本身的命名空间。
GetFactory方法首先查找本地app.config文件,然后查看machine.config。只需确保您确实有对SQLite程序集的引用,就像您所做的那样。
https://stackoverflow.com/questions/49659867
复制相似问题