我无法通过breeze.savechanges()来检测实体更改。我想要的只是简单地创建新的 order-> orderdetails 相关实体,修改它然后保存更改但是非常失败,所以我在一个名为 data 的工厂中拥有breeze管理器是我的控制者
angular.module("InventoryApp")
.controller("PurchasesCtrl", function ($scope, data, $log) {
var setFields=function(){
var product = data.createEntity("Product");
var purchaseOrder=data.createEntity("PurchaseOrder");
$scope.purchaseOrder = purchaseOrder;
$scope.product = product; //binding entities to view for edits
};
$scope.save = function(product, purchaseOrder) { //i am calling this from view
purchaseOrder.Time = new Date();
product.PurchaseOrders.push(purchaseOrder); //creating a relation
data.saveChanges(); //breeze refuses to save claim it have no changes
setFields(); //binding new fresh enties
};
setFields(); //binding new entities to view for edits
});
我已经尝试了data.saveChanges([product,purchaseOrder])
但是我在产品和购买之间的关系有些丢失,服务器在purchaseOrder中返回验证错误,它必须有一个有效的产品(它不会与我发送的新产品相关联? )
data.saveChanges([product])
只会保存产品并忽略PurchaseOrder,尽管product.PurchaseOrders.push(purchaseOrder);
正在工作。
使用purchaseOrder.Product=product;
代替product.PurchaseOrders.push(purchaseOrder);
来创建关系提供相同的故事。
在使用开发工具进行调试时,关系看起来完美脱机的方式,但是当我通过强制发送实体时,breeze管理器hasChanges frag不会变为true,服务器会出现错误。
我怀疑元数据是问题,因为服务器生成将其保存在Metadata.js上并在app.run期间提供给应用程序,但这里是元数据。
{
"schema": {
"namespace": "Inventory.API",
"alias": "Self",
"annotation:UseStrongSpatialTypes": "false",
"xmlns:annotation": "http://schemas.microsoft.com/ado/2009/02/edm/annotation",
"xmlns:customannotation": "http://schemas.microsoft.com/ado/2013/11/edm/customannotation",
"xmlns": "http://schemas.microsoft.com/ado/2009/11/edm",
"cSpaceOSpaceMapping": "[\"Inventory.API.Product\",\"Inventory.API.Entities.Product\"],[\"Inventory.API.PurchaseOrder\",\"Inventory.API.Entities.PurchaseOrder\"],[\"Inventory.API.SellOrder\",\"Inventory.API.Entities.SellOrder\"]",
"entityType": [{
"name": "Product",
"customannotation:ClrType": "Inventory.API.Entities.Product, Inventory.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": {
"propertyRef": {
"name": "Id"
}
},
"property": [{
"name": "Id",
"type": "Edm.Guid",
"nullable": "false",
"annotation:StoreGeneratedPattern": "Identity"
}, {
"name": "BarCode",
"type": "Edm.String",
"maxLength": "Max",
"fixedLength": "false",
"unicode": "true"
}, {
"name": "Name",
"type": "Edm.String",
"maxLength": "Max",
"fixedLength": "false",
"unicode": "true"
}, {
"name": "UnitPrice",
"type": "Edm.Decimal",
"precision": "18",
"scale": "2",
"nullable": "false"
}, {
"name": "Count",
"type": "Edm.Decimal",
"precision": "18",
"scale": "2",
"nullable": "false"
}],
"navigationProperty": [{
"name": "PurchaseOrders",
"relationship": "Self.PurchaseOrder_Product",
"fromRole": "PurchaseOrder_Product_Target",
"toRole": "PurchaseOrder_Product_Source"
}, {
"name": "SellOrders",
"relationship": "Self.SellOrder_Product",
"fromRole": "SellOrder_Product_Target",
"toRole": "SellOrder_Product_Source"
}]
}, {
"name": "PurchaseOrder",
"customannotation:ClrType": "Inventory.API.Entities.PurchaseOrder, Inventory.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": {
"propertyRef": {
"name": "Id"
}
},
"property": [{
"name": "Id",
"type": "Edm.Guid",
"nullable": "false",
"annotation:StoreGeneratedPattern": "Identity"
}, {
"name": "Time",
"type": "Edm.DateTime",
"nullable": "false"
}, {
"name": "UnitPrice",
"type": "Edm.Decimal",
"precision": "18",
"scale": "2",
"nullable": "false"
}, {
"name": "Count",
"type": "Edm.Decimal",
"precision": "18",
"scale": "2",
"nullable": "false"
}, {
"name": "TotalPrice",
"type": "Edm.Decimal",
"precision": "18",
"scale": "2",
"nullable": "false"
}],
"navigationProperty": {
"name": "Product",
"relationship": "Self.PurchaseOrder_Product",
"fromRole": "PurchaseOrder_Product_Source",
"toRole": "PurchaseOrder_Product_Target"
}
}, {
"name": "SellOrder",
"customannotation:ClrType": "Inventory.API.Entities.SellOrder, Inventory.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": {
"propertyRef": {
"name": "Id"
}
},
"property": [{
"name": "Id",
"type": "Edm.Guid",
"nullable": "false",
"annotation:StoreGeneratedPattern": "Identity"
}, {
"name": "Time",
"type": "Edm.DateTime",
"nullable": "false"
}, {
"name": "UnitPrice",
"type": "Edm.Decimal",
"precision": "18",
"scale": "2",
"nullable": "false"
}, {
"name": "Count",
"type": "Edm.Decimal",
"precision": "18",
"scale": "2",
"nullable": "false"
}, {
"name": "TotalPrice",
"type": "Edm.Decimal",
"precision": "18",
"scale": "2",
"nullable": "false"
}],
"navigationProperty": {
"name": "Product",
"relationship": "Self.SellOrder_Product",
"fromRole": "SellOrder_Product_Source",
"toRole": "SellOrder_Product_Target"
}
}],
"entityContainer": {
"name": "InventoryContext",
"customannotation:UseClrTypes": "true",
"entitySet": [{
"name": "Products",
"entityType": "Self.Product"
}, {
"name": "PurchaseOrders",
"entityType": "Self.PurchaseOrder"
}, {
"name": "SellOrders",
"entityType": "Self.SellOrder"
}],
"associationSet": [{
"name": "PurchaseOrder_Product",
"association": "Self.PurchaseOrder_Product",
"end": [{
"role": "PurchaseOrder_Product_Source",
"entitySet": "PurchaseOrders"
}, {
"role": "PurchaseOrder_Product_Target",
"entitySet": "Products"
}]
}, {
"name": "SellOrder_Product",
"association": "Self.SellOrder_Product",
"end": [{
"role": "SellOrder_Product_Source",
"entitySet": "SellOrders"
}, {
"role": "SellOrder_Product_Target",
"entitySet": "Products"
}]
}]
}
}
有什么想法吗?