开发者

In WCF Data Services, can I enclose a list of references to another entity while creating a new object?

开发者 https://www.devze.com 2023-01-24 22:58 出处:网络
I have a table Article, a table Tag and 开发者_如何学Pythona joint table to associate a tag to an article.

I have a table Article, a table Tag and 开发者_如何学Pythona joint table to associate a tag to an article.

While creating a new Article, by sending a POST request to /Service.svc/Articles, is it possible to enclose in the JSON object a list of Tag ids to be associated?

Something like:

{
  title: "My article title",
  text: "The content:",
  Tags: [ { id: 1 }, { id: 2 }, { id: 3 } ]
}

If not can I send the list of tags in one request? For example:

/Service.svc/Articles(1)/Tags

[ { id: 1 }, { id: 2 }, { id: 3 } ]

Or do I have to make as many requests as they are tags?

Thank you very much in advance.


You can modify just the links by POST/PUT/DELETE to the $links URL as described here: http://www.odata.org/developers/protocols/operations#CreatingLinksbetweenEntries The samples there use ATOM/XML, but the respective JSON format is also possible. To send multiple operations to the server in one request (to save the roundtrips) you can create a batch request as described here: http://www.odata.org/developers/protocols/batch

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号