如何使用OData 4和WebApi为无类型实体模型实现PATCH?

时间:2017-02-07 13:35:37

标签: asp.net-web-api odata

在使用OData 4和WebApi创建无类型实体模型时,我在使用PATCH时遇到了一些困难。 我创建了这个控制器方法:

[HttpPatch]
public IHttpActionResult Patch([FromODataUri] int key, Delta<EdmEntityObject> delta)
{
  // ...
}

当(attemting to)命中它时,我得到以下异常。 你应该实现自己的MediaTypeFormatter吗?你不应该使用application / json吗?或者有一个我不知道的技巧?

{
  "error": {
    "code": "",
    "message": "The request entity's media type 'application/json' is not supported for this resource.",
    "innererror": {
      "message": "No MediaTypeFormatter is available to read an object of type 'Delta`1' from content with media type 'application/json'.",
      "type": "System.Net.Http.UnsupportedMediaTypeException",
      "stacktrace": "   at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n   at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)"
    }
  }
}

0 个答案:

没有答案