如何在多个实体框架上下文中使用Breeze [英] How to use Breeze with multiple Entity Framework Contexts

查看:51
本文介绍了如何在多个实体框架上下文中使用Breeze的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让单个Breeze控制器与多个EF上下文一起使用是否可行或可行?每个上下文都有不同的数据模型。

Is it possible or practical to get a single Breeze controller to work with multiple EF contexts? Each context has a different data model.

或者,单个Breeze客户端是否可以使用两个不同的Breeze控制器?

Or, is it possible to have a single Breeze client use two different Breeze controllers?

推荐答案

两者都是可能的。两者都很常见。

Both are possible. Both are common.

通常,每个控制器都有一个EF-Context。那当然是简单的路径(但不是唯一可能的路径!)。

Usually you would have one-EF-Context-per-controller. That is certainly the easy path (but not the only possible path!).

在客户端上,您可以将它们视为独特的数据服务。在两种情况下,类似以下内容:

On the client, you could treat these as distinct "data services". Something like the following in the two-context case:


// Highly condensed, simplified example
var fooServiceName = 'api/foo';
var barServiceName = 'api/bar';

var fooManager = new breeze.EntityManager(fooServiceName);
var barManager = new breeze.EntityManager(barServiceName);

// use each manager in its own workflow

我的假设是您拥有单独的模型,因为您拥有单独的工作流程。该假设通常成立,并且肯定是最简单的方法。

My assumption is that you have separate models because you have separate workflows. That assumption usually holds and is certainly the easiest way to proceed.

然后,我会将客户端应用程序构造为单独的客户端模块,每个模块都有自己的 EntityManager

I then would structure my client application as separate client-side modules, each with its own EntityManager.

我不会再猜测了;让我们知道这是否适合您的目的或您是否有其他需要。

I won't speculate further; let us know if this suits your purpose or if you have some other need in mind.

顺便说一句,我宁愿控制器本身也不了解EF上下文。 。我希望看到它们隔离在支持外部类中,以便于测试。但是,关于您问题的实质,您应该没事。

As an aside, I would rather the controllers themselves not know about EF contexts at all. I'd like to see them isolated in supporting external classes for easier testing. But, regarding the essence of your question, you should be fine.

这篇关于如何在多个实体框架上下文中使用Breeze的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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