DbProviderFactory上的实体连接 [英] Entity Connection over DbProviderFactory
问题描述
大家好朋友,你好,b $ b b $ b b b我有一个普遍的问题。我有两个Ado.Provdier dll,一个在GAC中,一个与我的应用程序并排。
现在我尝试通过DBProviderFactory获取EntityConnection。
在appconfig中,我以这种方式注册并排dll:
Hello at frist to all,
i have a general question. I have two Ado.Provdier dlls, one is in GAC and one side by side with my application.
Now i try to get an EntityConnection over an DBProviderFactory.
In the appconfig i register the side-by-side dll in this way:
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite"/>
<add name="Fixed SQLite Data Provider"
invariant="System.Data.SQLite"
description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=cce5eb285696ae6e" />
</DbProviderFactories>
</system.data>
此程序集与GAC中的程序集具有差异标记。
现在我的代码以这种方式获得连接:
this assembly has a differend token to the one in GAC.
now my code to get the connection looks this way:
DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite");
using (DbConnection cnn = fact.CreateConnection())
{
cnn.ConnectionString = BuildDbConnectionString(this.serverDBFilePath, new StringBuilder()).ToString();
Assembly ____ = Assembly.GetAssembly(this.GetType());
MetadataWorkspace workspace = new MetadataWorkspace(new string[] { "res://*/" }, new Assembly[] { ____ });
EntityConnection ecnn = new EntityConnection(workspace, cnn);
return ecnn;
}
直到行" MetadataWorkspace 工作区 = new MetadataWorkspace ( new string [] { " res:// * /" }, new 汇编 [] { ____ });"
一切正常。我得到了我特殊的providerfactory和一个有效的数据库连接。
但是现在非常紧张的事情发生了。 MetadataWorkspace 从GAC加载程序集。
$
为什么会出现这种情况为什么MetaDataW。不要使用DBProviderFactory来获得正确的程序集???
i不明白这一事实。
我怎样才能避免这种情况?
请帮忙,请不要说"sqlite pado.net提供商的问题"因为它没有。它是一个装配解决EntityFramework的问题。
感谢你的帮助一百万次。
until the line "MetadataWorkspace workspace = new MetadataWorkspace(new string[] { "res://*/" }, new Assembly[] { ____ });"
all works great. I get my special providerfactory and a valid db connection.
But now very strainge things happens. the MetadataWorkspace loads the assembly from the GAC.
Why does this happens why does the MetaDataW. dont use the DBProviderFactory to get the right assembly???
i dont understand this fact.
How can i avoid from that?
Please help, and please do not say "its a problem from sqlite pado.net provider" because its not. Its a assembly resolve problem of the EntityFramework.
Thank one million times for your help.
推荐答案
您好Steffan,
Hi Steffan,
您是否在上一行获得了正确的汇编?
Are you getting the correct Assembly in the previous line?
谢谢,
Cathy Miller
Cathy Miller
Microsoft在线社区支持
Microsoft Online Community Support
这篇关于DbProviderFactory上的实体连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!