I have a simple breeze/knockout based SPA. I had to implement a "single save" option for a list of entities - editing was to be done on the list not in a separate popup.
On saving the server would check that only certain attrs of the entity were updated and also update a "last updated date" attr.
The list of entities was pulled up from the server by one Entity Manager.
To enable the single save the updated and ready to save entity was exported from the main Entity Manager and imported into a temporary entity manager. The save is performed and (if ok) the object re-exported and imported back into the main entity manager.
function saveSingle(entity)
{
var tempMgr = MainEntityManager.createEmptyCopy();
var exp = MainEntityManager.exportEntities([entity]);
tempMgr.importEntities(exp, {
mergeStrategy: breeze.MergeStrategy.PreserveChanges });
tempMgr.saveChanges()
.then(function (saveResult) {
var reImp = tempMgr.exportEntities();
MainEntityManager.importEntities(reImp);
entity.Last_Updated_Date(saveResult.entities[0].Last_Updated_Date());
entity.entityAspect.entityState = breeze.EntityState.Unchanged;
logger.success("changes saved");
})
.fail(function () {
logger.error("Single Save failed: " + error.message);
});
}
However, it looks like the new "last updated date" value does not get copied over after the save in the re-export/import back to the MainEntityManager process. I have worked around this but I'm wondering if I've done something wrong in this implementation and whether there is a better way to construct the "single entity save" feature?
Comments and questions welcome!