Steve Schmitt are right. My metadata.json had the "defaultResourceName" property with a different name that the database collection. I changed "Products" to "products" and this works.
Many thanks to all of you.
题
I am getting this error when running the sample application for AngularJS from Breeze's website.
This is the code for the controller breezectl.js:
'use strict';
angular.module('mean').controller('breezeController', ['$scope', 'Global', 'dataservice',
function($scope, Global, dataservice) {
$scope.global = Global;
$scope.breeze = {
name: 'Breeze Sample'
};
//$scope.results = dataservice;
function getProducts() {
function success(data) {
$scope.results = data;
}
function failed(error) {
$scope.results = error.message;
}
dataservice.getAllProducts()
.then(success)
.catch(failed);
}
getProducts();
}
]);
dataservice.getAllProducts()
enters the catch(failed) branch with this error message: "A MergeStrategy of 'Disallowed' does not allow you to attach an entity when an entity with the same key is already attached"
This is the code for dataservice.js:
'use strict';
angular.module('mean').factory('dataservice', ['breeze', 'entityManagerFactory',
function(breeze, entityManagerFactory) {
var manager = entityManagerFactory.newManager();
function getAllProducts(){
function success(data) {
return data.results;
}
return breeze.EntityQuery.from('Products')
.using(manager).execute()
.then(success);
}
var service = {
getAllProducts: getAllProducts
};
return service;
}
]);
Note: A direct call to Products from the Restful API (localhost:3000/breeze/northwind/Products
) works properly and returns a set of Json objects representing all of the products in the collection.
解决方案
Steve Schmitt are right. My metadata.json had the "defaultResourceName" property with a different name that the database collection. I changed "Products" to "products" and this works.
Many thanks to all of you.