entity-framework - 将动态连接字符串与 Breeze EFContextProvider 一起使用

标签 entity-framework breeze

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/

相关文章:

entity-framework - ASP.NET MVC 2.0 在jqgrid中搜索的实现

c# - Entity Framework 。违反 UNIQUE KEY 约束

.NET Entity Framework "remembering"数据库名称不存在

knockout.js - knockout - 使用 foreach 并一起排序

javascript - 轻松解决冲突

c# - Code First from Database - 无法将 NULL 值插入列 'Id',但值实际上不为 null

sql - 带有sql索引的查询的EF转换

breeze - 使用自定义 EFContextProvider 进行服务器端验证

angularjs - Hot Towel Angular-Breeze 类(class) - 出现 BreezeProvider 错误

angularjs - 我的 Breeze 脚本中不推荐使用的方法的版本问题