当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net mvc 4 - what is patch in ODATA?

问题描述:

What is use patch in odata?

How patch work ?

I find many example for odata but i can't understand patch which situation i can use patch.

Below is just example for patch

Partial Updates (PATCH requests)

public HttpResponseMessage PatchProduct(int id, Delta<Product> product)

{

Product dbProduct = _db.Products.SingleOrDefault(p => p.ID == id);

if (dbProduct == null)

{

throw new HttpResponseException(HttpStatusCode.NotFound);

}

product.Patch(dbProduct);

_db.SaveChanges();

return Request.CreateResponse(HttpStatusCode.NoContent);

}

网友答案:

PUT request have replace semantics which makes updates all or nothing, meaning you have to send all the properties even if only a subset have changed.This is where PATCH comes in, PATCH allows clients to send just the modified properties on the wire, essentially allowing for partial updates.

Given this we simply retrieve the product from the database and then we call Patch to apply the changes requested to the entity in the database. Once that is done we call SaveChanges to push the changes to the database.

分享给朋友:
您可能感兴趣的文章:
随机阅读: