0
votes

I have a custom entity definition like:

    var Card = function () {};

    var cardInitializer = function (card) {

        // card.fields is defined in the metadata.
        // card._cfields is an in-memory only field
        // that breeze will not, and should not, track.
        // Thus it is being added in the initializer

        card._cfields = card.fields.slice();
    };

When the data loads from the server everything is fine. The card.fields array has the corresponding data.

EDITED: Added more info and code of how manager is being set up

But when the data is round-tripped in local storage via .exportEntities and importEntities, the child data defined in the metadata, represented by the property card.fields in this example, is not loaded (the Array has length 0) during the initializer call, though it is subsequently available on the entity after load has completed.

Here is how the manager is being initialized:

var metadataStore = new breeze.MetadataStore();
metadataStore.importMetadata(options.metadata);

var queryOptions = new breeze.QueryOptions( {
    fetchStrategy: breeze.FetchStrategy.FromLocalCache
});

var dataService = new breeze.DataService({
   serviceName: "none",
   hasServerMetadata: false
 });

manager = new breeze.EntityManager({
    dataService: dataService,
    metadataStore: metadataStore,
    queryOptions: queryOptions
});

entityExtensions.registerExtensions(manager, breeze);

var entities = localStorage[storage];

if(entities && entities !== 'null'){
    manager.importEntities(entities);
}
2

2 Answers

0
votes

Wow. You ask for free support from the harried developer of a free OSS product that you presumably value and then you shit on him because you think he was being flippant? And downgrade his answer.

Could you have responded more generously. Perhaps you might recognize that your question was a bit unclear. I guess that occurred to you because you edited your question such that I can see what you're driving at.

Two suggestions for next time. (1) Be nice. (2) Provide a running code sample that illustrates your issue.

I'll meet you half way. I wrote a plunker that I believe demonstrates your complaint.

It shows that the navigation properties may not be wired up when importEntities calls an initializer even though the related entities are in cache.

They do appear to be wired up during query result processing when the initializer is called.

I cannot explain why they are different in this respect. I will ask.

My personal preference is to be consistent and to have the entities wired up. But it may be that there are good reasons why we don't do that or why it is indeterminate even when processing query results. I'll try to get an answer as I said.

Meanwhile, you'll have to work around this ... which you can do by processing the values returned from the import:

var imported = em2.importEntities(exported);

FWIW, the documentation is silent on this question.

-1
votes

Look at the "Extending Entities" documentation topic again.

You will see that, by design, breeze does not know about any properties created in an initializer and therefore ignores such properties during serialization such as entity export. This is a feature not a limitation.

If you want breeze to "know" about an unmapped property you must define it in the entity constructor (Card)... even if you later populate it in the initialized function.

Again, best to look at the docs and at examples before setting out on your own.