在Breeze EFContextProvider中使用动态连接字符串 [英] Using a dynamic connection string with the Breeze EFContextProvider

查看:34
本文介绍了在Breeze EFContextProvider中使用动态连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


此刻,我有一个应用程序(web / silverlight),其中ObjectContext的连接字符串是动态的。它基于用户登录的方式,因为我的每个客户都有自己的数据库。即.. username @ domain。我正在尝试找到一种使用EFContextProvider的方法,该方法是通过将ObjectContext传递给构造函数,或者通过重写GetConnectionString(可悲的是,两者均不受支持)。

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.

有没有一种方法可以完成此操作,或者可以在某个地方下载EFContextProvider的源代码以便自己实现?

Is there a way to accomplish this, or can i download the source for the EFContextProvider somewhere so i can implement it myself ?

请先感谢。

此问题由Marcel发布在我们的IdeaBlade论坛上。由于我认为这对Breeze Stack Overflow社区很有用。

This question was posted by Marcel on our IdeaBlade forums. I am reposting the question and answer here since I think it will be useful to the Breeze Stack Overflow community.

推荐答案

您不应'不必下载源代码并对其进行修改,就这么简单。而且现在您不必

You shouldn't have to download the source and modify it for such a simple thing. And now you won't have to.

我们已将 EFContextProvider 的简单更新推送到GitHub。此更改将出现在下一个Breeze Runtime版本(> 0.81.2)中。

We've pushed to GitHub a simple update to EFContextProvider. This change will appear in the next Breeze Runtime version (> 0.81.2).

其中 EFContextProvider 用于创建 T(您的ObjectContext / DbContext)如下:

Where EFContextProvider used to create the 'T' (your ObjectContext/DbContext) as follows:


_context = new T();

它现在调用虚拟方法 T CreateContext(),默认实现是:

It now calls upon a virtual method, T CreateContext() instead, whose default implementation is:


protected virtual T CreateContext() {
    return new T();
}

覆盖并替换为 EFContextProvider 子类,您

NB:基础 EFContextProvider 仍会进行一些创建后的配置,以确保其行为符合我们的预期;我们不希望上下文进行任何延迟加载或创建代理。

N.B.: The base EFContextProvider will still do a little post-creation configuration to make sure it behaves as we expect; we don't want the context doing any lazy loading or creating proxies.

因此,如果'T'是 ObjectContext ,提供商将执行以下操作:

So if 'T' is an ObjectContext, the provider will do this:


objCtx.ContextOptions.LazyLoadingEnabled = false;

,如果'T'是 DbContext ,它将执行以下操作:

and if 'T' is a DbContext it will do this:


dbCtx.Configuration.ProxyCreationEnabled = false;
dbCtx.Configuration.LazyLoadingEnabled = false;

这篇关于在Breeze EFContextProvider中使用动态连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆