1
votes

When retrieving entities and metadata from the server my custom initializer functions are able to access thier navigation properties as expected. When exporting metadata and entities to localstorage and reimporting them the navigation properties are not available. I have ensured that the ctors and initializers are registered to the metadatastore before import as the methods are called. I took a look at the breeze source and it appears that the initialize functions are called prior to the item being fully populated and attached.

targetEntity = entityType._createEntityCore();
            updateTargetFromRaw(targetEntity, rawEntity, dataProps, true);
            if (newTempKeyValue !== undefined) {
                // fixup pk
                targetEntity.setProperty(entityType.keyProperties[0].name, newTempKeyValue);

                // fixup foreign keys
                if (newAspect.tempNavPropNames) {
                    newAspect.tempNavPropNames.forEach(function (npName) {
                        var np = entityType.getNavigationProperty(npName);
                        var fkPropName = np.relatedDataProperties[0].name;
                        var oldFkValue = targetEntity.getProperty(fkPropName);
                        var fk = new EntityKey(np.entityType, [oldFkValue]);
                        var newFkValue = tempKeyMap[fk.toString()];
                        targetEntity.setProperty(fkPropName, newFkValue);
                    });
                }
            }
            *targetEntity.entityAspect._postInitialize();*
            targetEntity = entityGroup.attachEntity(targetEntity, entityState);
            if (entityChanged) {
                entityChanged.publish({ entityAction: EntityAction.AttachOnImport, entity: targetEntity });
                if (!entityState.isUnchanged()) {
                    entityGroup.entityManager._notifyStateChange(targetEntity, true);
                }
            }
        }

        if (targetEntity) {
            targetEntity.entityAspect.entityState = entityState;
            if (entityState.isModified()) {
                targetEntity.entityAspect.originalValuesMap = newAspect.originalValues;
            }
            entityGroup.entityManager._linkRelatedEntities( targetEntity);
        }

If I move the post initialize call below the ._linkRelatedEntities call it appears to work exactly as the query materialization

if (targetEntity) {
            targetEntity.entityAspect.entityState = entityState;
            if (entityState.isModified()) {
                targetEntity.entityAspect.originalValuesMap = newAspect.originalValues;
            }
            entityGroup.entityManager._linkRelatedEntities( targetEntity);
            *targetEntity.entityAspect._postInitialize();*
        }

Am I missing something here? Is this the designed functionality? I have found a work around by passing in the EntityManager, setting the entityAspect manager and calling loadNavigationProperties however this seems redundant. Any insight fromt he Breeze folks would be greatly appreciated.

Thanks, Brad

1
Was this issue fixed for you in Breeze 1.4.1? I am experiencing a similar issue in Breeze 1.5.4...NoRyb

1 Answers

0
votes

Not sure but this issue might be related to a bug that we just fixed in Breeze 1.4.1 available now.