有没有办法使用 oModel.createEntity()
创建一个“临时”(或者我猜它被称为虚拟)深层实体?
我有一个名为 Timesheet 的实体,它与中断有关联,称为 ToBreaks。
现在我想通过使用在前端创建一个新实体oModel.createEntity("/TimesheetSet")
。
不幸的是,在所谓的虚拟新条目中,我的所有关联都丢失了。
因为我使用assications来绑定(bind)表,所以在创建虚拟新条目后,会触发后端调用TimesheetSet("id-04-123456789")/ToBreaks
导致“无效的键谓词”错误。
有没有办法用 OData V2 做到这一点?
更新 09.08.2016:
You can still try by just using the properties parameter with a nested entity set. As long as your OData service supports the corresponding deep create it should work:
我也尝试过这样的事情:
oModel.createEntry("/TimesheetEntry", {
Pernr: sPernr,
Begda: dBegda,
ToBreaks: [{
Pernr: sPernr,
Begda: dBegda
}]
});
ToBreaks
是关联的名称。在 OData 模型的虚拟条目中,关联的属性仍然缺失。我可以使用上面的代码创建新条目,但之后没有名为
ToBreaks
的属性在后端,我按照本教程实现 deep_create 方法:step-by-step-development-guide-for-createdeepentity-operation。我能够从 SAP 网关客户端中触发该方法。
最佳答案
来自 API docs :
Please note that deep creates (including data defined by navigationproperties) are not supported.
您仍然可以尝试使用
properties
具有嵌套实体集的参数。只要您的 OData 服务支持相应的深度创建,它就应该可以工作:properties could be an object which includes the desired properties and the values which should be used for the created entry.
关于odata - 如何使用 oModel.createEntry 创建深层实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38802780/