【发布时间】:2010-11-10 04:49:51
【问题描述】:
我在我的数据层(基于实体框架)中使用 DbProviderFactories,并且我的数据库使用 SQLite,但我不需要 App.Config 来获得以下代码:
<configuration>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite"/>
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
</configuration>
相反,我希望我的数据层以编程方式将其放入。有人知道这样做的方法吗?
编辑:
原因是我使用 IoC 容器来选择数据层,而我的一些数据层不需要 App.Config 值,或者将它们硬绑定到数据层。
【问题讨论】:
-
为什么没有 app.config。如果你不这样做(也许你是一个类库),那么调用应用程序就会这样做。把配置放在那里。
-
想知道 Jason 是否曾找到答案……我有一个 HTA,它将我们的 .Net 程序集称为 COM 对象。所以,没有app.config。我们正在使用 SQL CE,我们也面临同样的问题。
-
@JohnSaunders:对我来说,我试图让多个 exe 使用相同的配置文件。 EntityFramework 似乎没有兑现
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", @"C:\Shared\app.config");因此这个问题的用处。
标签: entity-framework sqlite ado.net dbproviderfactories