错误Breeze OData - http:// localhost:5781 / odata / $ metadata的元数据查询失败

时间:2014-06-03 16:33:36

标签: odata breeze

我在论坛上研究了问题,但没有找到真实的结果。

错误:

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

代码

(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;
    }


}})();

代码其他:

(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);
        }
    }
}})();

代码其他:

(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);
        });
    }
}}());

1 个答案:

答案 0 :(得分:0)

此问题很可能与camelCase命名约定以及您正在使用的语言和/或属性名称有关。我的猜测是,如果删除将camelCase设置为默认值的行,则错误将消失。如果是这样,那么您将需要编写自己的自定义命名约定。见http://www.breezejs.com/documentation/naming-convention

发生这种情况的原因(我在这里猜测)是,camelCase命名约定非常简单,可能不适用于您的属性名称和/或语言。它假定所有服务器属性名称都以大写字符开头,并且该字符可以转换为小写字符,并且此过程可以反转。我的猜测是你的一个属性名称已经有一个小写的第一个字符,或者在属性名称中的某个第一个字符上调用toLower / toUpper本身并不是往返的。 (这可能是一些非拉丁字符集)。

如果出现其中任何一种情况,实际上很容易创建自己的namingConvention而不是使用“camelCase”#39;再次看到上面提到的文档。