How to use Breeze with multiple Entity Framework Contexts

帅比萌擦擦* 提交于 2019-12-25 00:18:49

问题


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

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


回答1:


Both are possible. Both are common.

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.

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.

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.



来源:https://stackoverflow.com/questions/15661634/how-to-use-breeze-with-multiple-entity-framework-contexts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!