Question

I'm using breeze in one app for both client and server side. I use one Master Manager to get all the static data, like picklist's, combobox's, etc. I'm using another manager to edit data in my views.

I'm following the aproach sugested here: http://www.breezejs.com/documentation/multiple-managers#CreateMultipleManagers

But I have problem. My problem is how can i change information from Master Manager to my other Managers?

For example I have this model :

EntityA { Id , description }

EntityB { Id , EntityA(Navigation Property), EntityAId}

And I have this data in the model :

EntityA : 
1, 'Description 1' 
2, 'Description 2'
3, 'Description 3'

EntityB
1, EntityA , 1
2, EntityA , 3

In my view I have one list of entitiesB and when I choose one item to edit, I can change it's properties. After doing this, I want to update the item in the list displayed. So far so good, and this works perfectly with non referenced objects, like int, string's, etc... But when i try to update my EntityB navigation property in the same item, to display the correct description, the information isnt's update in the case of my view Manager doesn's know the object.

For example, if I choose to edit the first item of the list above.

  • When I set EntityB.EntityAId = 3. My view manager, update's the navigation property to the correct EntityA.
  • When I set EntityB.EntityAId = 2. My view Manager doesn't know who is EntityA = 2, so it doesn't update the information in the navigation property, and the description displayed in the view is still the original description or empty in the case of new List Item.

So my question is how can I tell to my view Manager, the correct object to display? Knowing that my Master Manager, knows who is that object.

I tried to do EntityA.EntityB = EntitiesB[someIndex] and this gives the following error :

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

*Answer :

  • I manually create the EntityB (unchanged) who didn't exist in the view Manager, and this works. I based this new entity on the selected EntityB from Master Manager.
  • The answer suggested bellow, also works fine.

In my application I used the two approaches depending on the context.

Was it helpful?

Solution

You can export entities from one manager and import them into another. For example

var arrayOfEntities = [ firstEntity, secondEntity, ... ]
var exportedEntities = entityManager1.exportEntities( arrayOfEntities, false);
var importedEntities = entityManager2.importEntities( exportedEntitites);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top