MVC Data v4 中 delta<TEntity> 的 json 格式是什么?

what is the json format for delta<TEntity> in MVC Data v4?

我有一个控制器:

public class PostsController : ODataController
{
    public IHttpActionResult Post(Post post) {}
    public IHttpActionResult Put([FromODataUri] int key, Delta<Post> patch) {}
}

Post 实体只有 2 个字段:int Idstring Content。 以下 json 消息在 POST 操作下运行良好:

{
  content: "dasdasd678678678"
}

但是,PUT 操作拒绝请求并返回 400 错误:

{
  "error":{
    "code":"","message":"The request is invalid.","innererror":{
      "message":"The parameters dictionary contains an invalid entry for parameter 'patch' for method 'System.Web.Http.IHttpActionResult Put(Int32, System.Web.OData.Delta`1[Post])' in 'NWeb.Controllers.API.PostsController'. The dictionary contains a value of type 'Entity.Post', but the parameter requires a value of type 'System.Web.OData.Delta`1[Entity.Post]'.","type":"","stacktrace":""
    }
  }
}

PUT 操作应如下所示 public IHttpActionResult Put([FromODataUri] int key, Post post) {}

并且 delta<Entity> 应该像这样与 PATCH 一起工作 public IHttpActionResult Patch([FromODataUri] int key, Delta<Post> post)

PUT 和 PATCH 都用于更新实体,但 PUT 需要更新实体的完整有效负载,而 PATCH 只需要增量信息。