gpt4 book ai didi

post - 使用扩展创建 OData POST 实体

转载 作者:行者123 更新时间:2023-12-04 12:41:51 33 4
gpt4 key购买 nike

我正在尝试同时创建一个实体和两个子实体的实例。

如果我将以下 JSON 发布到/user_objects 资源,它会很高兴地创建父 user_object 实体和链接的 User_object_attribute 实体。唯一的问题是我似乎无法扩展结果集以包含新的 user_object_attribute 所以我有效地拥有了 user_object 的最新版本,但我必须然后去读取 OData 服务,即另一个服务器命中为了检索 user_object_attributes。

返回后,我的 id 将整齐地放入子 user_object_attribute 对象中,但是如果 child 还有一个像 created_date 这样的服务器端生成的字段呢?那我还得再次点击OData repo吗?

我已经尝试了正确的 $expand 查询 ?$expand=user_objects_attributes,虽然创建成功,但我仍然没有返回扩展的结果集。

如果这可能的话,有人会知道吗?或者是不是因为这样做的唯一方法是返回所有子 user_object_attributes?

{
"annotator_id":1,
"content_type":"content_type",
"created_date":"2013-02-15T17:20:09.191",
"guid":"GUID",
"size_kb":100,
"title":"Title",
"updated_date":null,
"url":"URL",
"user_object_id":0,
"user_objects_attributes":[
{
"attribute_id":0,
"name":"name191",
"user_object_id":0,
"value":"value191"
}
]
}

谢谢,
标记。

最佳答案

查看 OData V3 规范 here :

In version 1.0 and version 2.0, if the insert succeeds in full, the server MUST return a response with a 201 (Created) status code and a response body that conforms to the syntax specified in InsertEntity Request (section 2.2.7.1.1). The response body MUST contain the values of the inserted resource after the server has executed all its server-specific data processing rules (validation, and so on). The server MAY alter the values of the resource received from the client before the resource is inserted on the server.

In version 3.0, the response MAY have a 204 status code, as specified in [RFC2616], based on the client preference (see Prefer (section 2.2.5.9)) on the InsertEntity Request.



不太清楚服务器应该做什么......只返回顶级创建的实体,或者该实体及其所有扩展链接。

我对 $expand 对 POST(或任何 CUD 请求)没有影响并不感到惊讶。如果它不是查询,WCF DS 可能会忽略它。根据规范,这可能是正确的。

坦率地说,我认为使用 WCF DS Server,您无法获得任何其他返回。在 V3 中,如果您指定标题表示您不需要任何内容​​,则您的实体(仅)会获得 201 或 204 无内容。

这是否符合 OData 标准...不完全确定:-)。无论如何,我认为此时您无法在 WCF DS 堆栈上获得所需的内容。

关于post - 使用扩展创建 OData POST 实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14900289/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com