BreezeJS - handling lookup tables across modules

前提是你 提交于 2019-12-13 21:32:47

问题


We have a large application that allows the user to switch between different modules within the application. Each module needs to be able to save separately, so each module has it's own EntityManager.

There are some lookup tables, though, that we would like to use across the application. If we load the lookup tables at the application level, using a different EntityManager, they are not very usable then within the modules.

For example, if I want to load a 'Countries' lookup table at the application level, I then can't do something as simple as:

Person.Country = lookupDataContext.getCountry('Norway')

if Person is within a module's EntityManager. I will get something like:

"An Entity cannot be attached to an entity in another EntityManager. One of the two entities must be detached first."

Am I understanding BreezeJS correctly? If so, does that mean I need to have the Countries lookup within each module's EntityManager? This seems very limiting.


回答1:


I believe this question is related to your other question about having multiple EntityManagers. Check out my general thoughts there which cover the scenario you describe here.

To be slightly more specific:

  • Breeze entities cannot navigate to related entities in a different EntityManager; that's what the error message is telling you.
  • You probably do want separate instances of the reference entities (such as Countries) in both managers.
  • You can easily copy any set of entities from one manager to another with export and import methods. You don't have to go back to the server.

Now, instead of a lookupDataContext, each sandbox datacontext can have a sandboxContext.lookups.countries method that delivers the appropriate entities from the proper sandbox manager.

Is this limiting? I don't think it's so bad as long as

  • you aren't duplicating an enormous amount of data across managers.
  • the reference entities are essentially immutable during a user session.
  • a user session doesn't keep too many sandbox managers alive at the same time
  • you dispose of or re-cycle the sandbox managers (and their datacontexts) when you're done with them.

You should be able to achieve your goal of loading lookups from the server once and managing them centrally in the master manager.

This approach has been very successful in a great number of applications over the last decade (pre-Breeze obviously).

HTH.



来源:https://stackoverflow.com/questions/30242279/breezejs-handling-lookup-tables-across-modules

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