I'm working on an SPA which is using breeze for data access. I want to create an instance of metadata as soon as possible, and I suppose that would be after this has completed initialization:
var manager = new entityModel.EntityManager(serviceName);
However, entity manager needs to perform ajax request to web api controller to load metadata, and if I try manager.metadataStore.getEntityType("EntityName")
before it is complete, I get:
Uncaught Error: Unable to locate an 'Type' by the name
My question is is there an event which is triggered when metadata is loaded? I wandered through documentation but it seems that I'm unable to find it.
As of Breeze 1.4.16, the MetadataStore now has a metadataFetched event, described here: http://www.breezejs.com/sites/all/apidocs/classes/MetadataStore.html#event_metadataFetched
The problem with the proposed solution is that fetchMetadata can fail ... for various reasons. If the failure is due to transient communication failure, then the next query call fetches the metadata and the app will start accessing data without having initialized whatever it needed to initialize WRT the metadata (in our case client-side validations). In our case, the app seems to work fine except there are no validations.
It's odd that this condition happens alot. The call to fetchMetadata fails, but subsequent queries succeed. Does not happen every time, but happens more than a little.
We could add a state to the system that prevents other data access until the fetchMetadata succeeds and retry it until it does succeed. But, that's alot of work. An event that fires when the load completes would be so much better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With