Search code examples
metadatabreeze

How to block EntityQuery to call metadata


I'm following SPA by John papa, I developed a sample application using Hottowel, Angular and Breeze.

On the application load I'm fetching the metadatastore

function fetchMetadataOnPageLoad()
{
  var store = manager.metadataStore;
            return store.fetchMetadata(serviceName)
            .then(gotMetadata)
            .catch(handleFail); 
}

In the above step the Metadata is being loaded from the server.

Then I navigated to some page and trying to fetch the data by following query

 function GetAllUsers()
        {
            manager = emFactory.newManager();
            var query = EntityQuery.from('users');
            manager.executeQuery(query)
                       .then(querySucceeded, _queryFailed);
        }`

`

Then I'm getting the following exception because the query is calling the server metadata method twice before execution but I have already fetched the metadata on the pageload.

Error:

Metadata query failed for: breeze/Breeze/Metadata. Unable to either parse or import metadata: Type already exists in this MetadataStore.; Server side errors encountered - see the entityErrors collection on this object for more detail

Is there any way to restrict the metadata call while executing the query.

Please correct me.

Thank you.

Hari C


Solution

  • When you create the EntityManager, tell it you'll retrieve the server metadata manually:

    var dataService = new breeze.DataService({
        serviceName: 'api/Datamart',
        hasServerMetadata: false // solution here - will prevent metadata call on 1st query
    });
    var store = new breeze.MetadataStore();
    
    store.fetchMetadata(dataService.serviceName)
        .then(function () {
            manager = new breeze.EntityManager({
                dataService: dataService,
                metadataStore: store
        });
    };