At the moment i have an application (web/silverlight) where the connectionstring for my ObjectContext is dynamic. It is based on how a user logs in because each of my customers have their own database. ie.. username@domain. I'm trying to find a way to use the EFContextProvider which would be by either passing the ObjectContext through the constructor, or by overriding the GetConnectionString, which sadly both aren't supported.
Is there a way to accomplish this, or can i download the source for the EFContextProvider somewhere so i can implement it myself ?
Thanks in advance.
这个问题是由 Marcel 在我们的 IdeaBlade 论坛上发布的。我在这里重新发布问题和答案,因为我认为它对 Breeze Stack Overflow 社区有用。
最佳答案
您不应该为了这么简单的事情下载源代码并对其进行修改。 现在您不必这样做了。
我们已将 EFContextProvider
的简单更新推送到 GitHub。此更改将出现在下一个 Breeze Runtime 版本 (> 0.81.2) 中。
其中EFContextProvider
用来创建'T'(你的ObjectContext/DbContext)如下:
_context = new T();
它现在调用一个虚拟方法,T CreateContext()
,其默认实现是:
protected virtual T CreateContext() { return new T(); }
在您的 EFContextProvider
子类中覆盖并替换它,您将能够按照自己喜欢的方式创建类型为“T”的上下文。
注意:基础 EFContextProvider
仍会进行一些创建后配置,以确保其行为符合我们的预期;我们不希望上下文进行任何延迟加载或创建代理。
所以如果'T'是一个ObjectContext
,提供者会这样做:
objCtx.ContextOptions.LazyLoadingEnabled = false;
如果 'T' 是 DbContext
它会这样做:
dbCtx.Configuration.ProxyCreationEnabled = false; dbCtx.Configuration.LazyLoadingEnabled = false;
关于entity-framework - 将动态连接字符串与 Breeze EFContextProvider 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13616832/