Vaccano
Vaccano

Reputation: 82437

Copy entities from one Breeze EntityManager to another EntityManager

This breeze documentation page has this sample for making a copy of an EntityManager:

function createManager() {
   // same configuration; no entities in cache.
   var manager = masterManager.createEmptyCopy(); 

   // ... copy in some entities (e.g.,picklists) from masterManager

   return manager;
}

I am not sure how I am supposed to do the "copy in some entities (e.g.,picklists) from masterManager" step.

I guess I could just go create the entities as if they are new. But they are not, they are picklist values that were queried from the database.

I thought about trying to use Export/Import, but that seems like it is intended for offline work and serializes all the values to string. (Which seems like it may not be as performant as what I would like.)

Is there "normal" way that everyone copies entities between EntityManagers?

Upvotes: 0

Views: 130

Answers (1)

Steve Schmitt
Steve Schmitt

Reputation: 3209

Yes, you copy the entities by exporting and importing. For performance, you should specify

  • asString: false, to avoid string serialization overhead, and
  • includeMetadata: false, since createEmptyCopy() creates an EntityManager that already has metadata

So:

function createManager() {
   // same configuration; no entities in cache.
   var manager = masterManager.createEmptyCopy(); 

   var entities = masterManager.exportEntities(null, { asString: false, includeMetadata: false });
   manager.importEntities(entities);

   return manager;
}

Upvotes: 1

Related Questions