To streamline the process of loading metadata without an additional network call to the server, embed it in your scripts and supply Breeze with it manually as recommended by @Ward.
Below is an example using TypeScript:
import { DataService, EntityManager, MetadataStore, NamingConvention } from "breeze-client";
// Your metadata object
const metadata: any = Metadata.value;
// define the Breeze `DataService` for this app
const dataService: DataService = new DataService({
serviceName: "http://localhost:63000",
hasServerMetadata: false // avoid requesting metadata from the server
});
// create the metadataStore
const metadataStore: MetadataStore = new MetadataStore({
namingConvention: NamingConvention.camelCase // utilize this convention if needed
});
// initialize it from the application's metadata variable
metadataStore.importMetadata(metadata);
const entityManagerConfig: EntityManagerOptions = {
dataService: dataService,
metadataStore: metadataStore
};
this.entityManager = new EntityManager(entityManagerConfig);
You now have an EntityManager
instance configured with the metadata and prepared to handle queries confidently.
For further details, refer to the official documentation