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.
There is no event, but you can call the MetadataStore.fetchMetadata method yourself and perform your logic in the ‘then’ part of the promise.
The MetadataStore.fetchMetadata method is automatically called internally by the first query against each server, if it hasn’t already been called..
So simply call MetadataStore.fetchMetadata yourself before the first query.
Hope this makes sense.