我正在尝试了解如何在odata v4中进行深度插入。Odata v4规范指出深度插入是可能的。但我已经尝试了几种方法,但都无法找到解决方案。每当我试图发布一个带有导航数据的实体时,服务器端都会收到null。任何人对此都有任何想法。感谢
我不知道你使用的是什么服务端。但是,Web API OData支持发布具有导航属性的实体。
例如,您的控制器中有一个Post方法:
[HttpPost]
public IHttpActionResult Post(Customer customer)
{
int key = _customers.Count();
customer.Id = key + 1;
_customers.Add(customer);
return Created(customer);
}
您可以在http://..../odata/Customers
上发出POST请求,请求负载示例如下:
User-Agent: Fiddler
Host: localhost:33082
Content-Type: application/json
Content-Length: 134
{
"Id":9,
"Name":"Customer #9",
"Orders":[
{
"OrderId":2,"Price":3.3
}
]
}
谢谢。