无法在breezejs中保存关系实体
Cant Save relational Entities in breezejs
我有两个通过 manager.createEntity(type);
创建的实体。如果我尝试以其他方式创建它们,z-validate 不会显示验证错误
..entity orderdetails 必须具有来自 order 的有效密钥。后来...
... //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"
}]
}
}
}
您需要映射 OrderDetail
和 DifferentDetail
实体的 orderId
外键 属性。当 Breeze 将实体发送到服务器时,它使用外键传达实体之间的关系。
我需要映射 OrderDetail 和 DifferentDetail 实体的 orderId 外键 属性。当 Breeze 将实体发送到服务器时,它使用外键传达实体之间的关系。
... 关系存在,但 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 类 中创建了一个新的元数据副本。
我有两个通过 manager.createEntity(type);
创建的实体。如果我尝试以其他方式创建它们,z-validate 不会显示验证错误
..entity orderdetails 必须具有来自 order 的有效密钥。后来...
... //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"
}]
}
}
}
您需要映射 OrderDetail
和 DifferentDetail
实体的 orderId
外键 属性。当 Breeze 将实体发送到服务器时,它使用外键传达实体之间的关系。
我需要映射 OrderDetail 和 DifferentDetail 实体的 orderId 外键 属性。当 Breeze 将实体发送到服务器时,它使用外键传达实体之间的关系。
... 关系存在,但 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 类 中创建了一个新的元数据副本。