Error Breeze OData - Metadata query failed for http://localhost:5781/odata/$metadata

StackOverflow https://stackoverflow.com//questions/24020397

  •  21-12-2019
  •  | 
  •  

Question

I researched questions on forum but not find true result.

Error:

Metadata query failed for //localhost:5781/odata/$metadata; Unable to process returned 

metadata: NamingConvention for this server property name does not roundtrip 

properly:diagram_id-->Diagram_id Error: Metadata query failed for //localhost:5781/odata/$metadata; Unable to process returned metadata: NamingConvention for this server property name does not roundtrip properly:diagram_id

Code

(function () {
'use strict';

var serviceId = 'entityManagerFactory';
angular.module('myApp')
       .factory(serviceId, ['breeze', emFactory]);

function emFactory(breeze) {
    configureBreeze();
    var serviceRoot = window.location.protocol + '//' + window.location.host + '/';
    var serviceName = serviceRoot + 'odata/';
    var factory = {
        newManager: newManager,
        serviceName: serviceName
    };

    return factory;

    function configureBreeze() {
        // use Web API OData to query and save
        breeze.config.initializeAdapterInstance('dataService', 'webApiOData', true);

        // convert between server-side PascalCase and client-side camelCase
        breeze.NamingConvention.camelCase.setAsDefault();
    }

    function newManager() {
        var mgr = new breeze.EntityManager(serviceName);
        return mgr;
    }


}})();

Code other :

(function () {
'use strict';
var serviceId = 'datacontext';
angular.module('myApp')
.factory(serviceId, ['$q', 'logger', 'entityManagerFactory', datacontext]);

function datacontext($q,logger,emFactory) {
    logger = logger.forSource(serviceId);
    var logError = logger.logError;
    var logSuccess = logger.logSuccess;
    var logWarning = logger.logWarning;

    var manager = emFactory.newManager();

    var service = {
        getEmployees: getEmployees
    };
    return service;

    /*Hiện thực ở đây*/
    function getChangesCount(){
        return manager.getChanges().length;
    }

    function getEmployees(forceRefresh) {
        var count;
        if (forceRefresh) {
            if(manager.hasChanges()){
                count = getChangesCount();
                manager.rejectChanges();//undo tất cả các thay đổi ko được lưu
                logWarning('Số nhân viên' + count + 'bị thay đổi', null, true);
            }
        }
        // Lúc ko có forceRefesh,xem xét nhận bộ nhớ cache hơn từ xa
        return breeze.EntityQuery.from('Employees')
                        .using(manager).execute()
                        .then(success).catch(failed);
        function success(response) {
            count = response.results.length;
            logSuccess('Đã nhận ' + count + ' nhân viên', response, true);
            return response.results;
        }
        function failed(error) {
            var message = error.message || "Truy vấn để bảng nhân viên bị lỗi";
            logError(message, error, true);
        }
    }
}})();

Code other :

(function () {
'use strict';

var controllerId = 'employees';
angular.module('myApp')
.controller(controllerId, ['datacontext', 'logger', employees]);

function employees(datacontext, logger) {
    logger = logger.forSource(controllerId);
    var logError = logger.logError;
    var logSuccess = logger.logSuccess;

    var vm = this;
    vm.employees = [];

    initialize();

    /*Hiện thực*/
    function initialize() {
        getEmployees();
    }

    function getEmployees(forceRefresh) {
        return datacontext.getEmployees(forceRefresh).then(function (data) {
            return vm.employees = data;
            console.log(data);
        });
    }
}}());
Was it helpful?

Solution

This problem very likely has to do with the camelCase naming convention and the language and/or property names that you are using. My guess is that if you remove the line that sets camelCase as the default then the error will go away. If so, then you will need to write your own custom naming convention. See http://www.breezejs.com/documentation/naming-convention

The reason that this is occurring, (I'm guessing here), is that the camelCase naming convention is very simplistic and may not work for your property names and/or language. It assumes that all server property names begin with an uppercase character and that this character can be converted to a lowercase character, and further that this process can be reversed. My guess is that one of your property names already has a first character that is lower case or that calling toLower/toUpper on some first character in a property name does not itself roundtrip. (This can occur is some non-latin character sets).

If either of these cases is occuring, its actually rather easy to create your own namingConvention to use instead of 'camelCase'. Again see the docs mentioned above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top