问题
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