我需要让 DbProviderFactories.GetFactory() 返回 Sqlite 的提供程序。但是,我已通过 NuGet 将 Sqlite 添加到我的项目中,并且希望避免将其放入 GAC 并更新 machine.config。Sqlite 的优点之一是无需配置。
但是,我有许多从 GetFactory() 中提取连接器的库。
有没有办法做到这一点?
谢谢 - 戴夫
我需要让 DbProviderFactories.GetFactory() 返回 Sqlite 的提供程序。但是,我已通过 NuGet 将 Sqlite 添加到我的项目中,并且希望避免将其放入 GAC 并更新 machine.config。Sqlite 的优点之一是无需配置。
但是,我有许多从 GetFactory() 中提取连接器的库。
有没有办法做到这一点?
谢谢 - 戴夫
您只需将 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 程序集的引用,就像你做的那样。