问题
I want to have a route like:
/Accounts(id)/Orders
where I can execute a POST to create an order. I can't find a way to add this route using OData in WebApi. For GET there is a convention to follow to get related collections, but I am not able to find any convention for posting new entities to a related collection.
Is there a standard way to handle this POST request with Web API 2 and OData 4 ?
回答1:
Added the following attributes to the method and it worked:
[HttpPost]
[ODataRoute("Accounts({key})/Orders")]
public IHttpActionResult Orders([FromODataUri] string key, OrderDto orderDto)
{
}
来源:https://stackoverflow.com/questions/27506627/post-to-a-related-collection-in-web-api-2-with-odata-4