2012-04-03 47 views
0

我有批量更新数据的请求。 数据为:更改集中的OData引用请求

Item : { 
id : int, 
name : string,  
RefItem : { 
    int : id, 
    name : string } 
} 

我需要

  1. 创建项目
  2. 这个新创建的项目更新RefItem参考,在同一批次。 (假设RefItems(1)中的数据集已经存在)

根据OData的规格:

--batch_1872-f36a-7ce8

Content-Type: multipart/mixed; boundary=changeset_8c16-9ba3-2260

--changeset_8c16-9ba3-2260

Content-Type: application/http

Content-Transfer-Encoding: binary

PUT $1/$links/ItemRef HTTP/1.1

Content-ID: 2

Accept: application/atomsvc+xml;q=0.8, application/json;q=0.5, /;q=0.1

DataServiceVersion: 1.0

Content-Type: application/json

{"uri":"ItemRefs(1)"}

--changeset_8c16-9ba3-2260

Content-Type: application/http

Content-Transfer-Encoding: binary

POST Products HTTP/1.1

Content-ID: 1

Accept: application/atomsvc+xml;q=0.8, application/json;q=0.5, /;q=0.1

DataServiceVersion: 1.0

Content-Type: application/json

{"id":-1,"name":"seven"}

--changeset_8c16-9ba3-2260--

--batch_1872-f36a-7ce8--

我想它应该工作,但我有响应错误:

--batchresponse_4febeba8-dd43-4040-9fdb-866afde5304e Content-Type: multipart/mixed; boundary=changesetresponse_424dbf12-fa9a-4a59-8284-963fa0fa7b77

--changesetresponse_424dbf12-fa9a-4a59-8284-963fa0fa7b77 Content-Type: application/http Content-Transfer-Encoding: binary

HTTP/1.1 500 Internal Server Error Content-ID: 2 X-Content-Type-Options: nosniff DataServiceVersion: 1.0; Content-Type: application/json;charset=utf-8

{"d":{"error":{"code":"","message":{"lang":"ru-RU","value":"An error occurred while processing this request."}}}} --changesetresponse_424dbf12-fa9a-4a59-...

有人可以告诉我我错了吗? 谢谢。

回答

0

批处理请求将作为流进行处理。所以你只能参考已经看到的内容ID。上述示例在请求操作之前使用该内容ID引用内容ID 1。这是无效的。

您需要先创建新实例(POST),然后通过$ links URL添加对它的引用。