我有两个通过manager.createEntity(type);
创建的实体.. z-validate如果我尝试创建验证错误,则不会显示验证错误
..entity orderdetails 必须包含来自订单的有效密钥。以后......
... //changed some stuff but never keys
orderdetails.Time = new Date();
orderdetails.order = order; //am i creating the relation right here?
该应用程序可以脱机工作,但是当我将更改保存到服务器时..
manager.saveChanges([order,orderdetails]);
服务器正在返回
...orderdetails","KeyValues":["fd...28"],"PropertyName":"order",ErrorMessage":"The order field is required."
知道我怎么能经历这个?我好几天都在阅读文件。
元数据看起来像这样
{
"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.Order\",\"Inventory.API.Entities.Order\"],[\"Inventory.API.OrderDetail\",\"Inventory.API.Entities.OrderDetail\"],[\"Inventory.API.DifferentDetail\",\"Inventory.API.Entities.DifferentDetail\"]",
"entityType": [ {
"name": "Order",
"customannotation:ClrType": "Inventory.API.Entities.Order, 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": "OrderDetails",
"relationship": "Self.OrderDetail_Order",
"fromRole": "OrderDetail_Order_Target",
"toRole": "OrderDetail_Order_Source"
}, {
"name": "DifferentDetails",
"relationship": "Self.DifferentDetail_Order",
"fromRole": "DifferentDetail_Order_Target",
"toRole": "DifferentDetail_Order_Source"
}]
}, {
"name": "OrderDetail",
"customannotation:ClrType": "Inventory.API.Entities.OrderDetail, 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": "Order",
"relationship": "Self.OrderDetail_Order",
"fromRole": "OrderDetail_Order_Source",
"toRole": "OrderDetail_Order_Target"
}
}, {
"name": "DifferentDetail",
"customannotation:ClrType": "Inventory.API.Entities.DifferentDetail, 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": "Order",
"relationship": "Self.DifferentDetail_Order",
"fromRole": "DifferentDetail_Order_Source",
"toRole": "DifferentDetail_Order_Target"
}
}],
"entityContainer": {
"name": "InventoryContext",
"customannotation:UseClrTypes": "true",
"entitySet": [{
"name": "Orders",
"entityType": "Self.Order"
}, {
"name": "OrderDetails",
"entityType": "Self.OrderDetail"
}, {
"name": "DifferentDetails",
"entityType": "Self.DifferentDetail"
}],
"associationSet": [{
"name": "OrderDetail_Order",
"association": "Self.OrderDetail_Order",
"end": [{
"role": "OrderDetail_Order_Source",
"entitySet": "OrderDetails"
}, {
"role": "OrderDetail_Order_Target",
"entitySet": "Orders"
}]
}, {
"name": "DifferentDetail_Order",
"association": "Self.DifferentDetail_Order",
"end": [{
"role": "DifferentDetail_Order_Source",
"entitySet": "DifferentDetails"
}, {
"role": "DifferentDetail_Order_Target",
"entitySet": "Orders"
}]
}
}
}
答案 0 :(得分:1)
您需要映射orderId
和OrderDetail
实体的DifferentDetail
外键属性。当Breeze将实体发送到服务器时,它使用外键传递实体之间的关系。
答案 1 :(得分:0)
我需要映射OrderDetail和DifferentDetail实体的orderId外键属性。当Breeze将实体发送到服务器时,它使用外键传递实体之间的关系。
......关系在那里,但微风不会看到它,因为它被定义为像这样
[Required]
public Order Order { get; set; }
因此我将其更改为
[Required]
public Guid Order_Id { get; set; }
[ForeignKey("Order_Id")]
public virtual Order Order{get; set;}
然后在DBContext中的POCO类创建了元数据的新副本。