To update an entity in ASP.NET Web API, PUT request is used and we have to send all the properties even if only a subset have changed means if only one field is updated on the client side, we have to send the entire model back to the server to make an update. It’s not a cool way. PATCH request allows you to send just the modified properties for partial model updates. It reduces complexity in case of bigger tables. Here is a usage example to implement HTTP Patch request in ASP.NET Web API to update data with EF DB First.

In above method, we are using Delta<DocInfo> type argument instead of DocInfo. Delta<DocInfo> allows to set any DocInfo property and also track which properties are set. Delta class provides Patch method which copies the properties that have been set.

Note: oData 0.2.0 alpha is used. It may be subject to change. You can get new nuget package for building OData.

Client Side:

We are going to update only Revision property for a particular document. For simplicity, we are taking same app to consume web API and using following ajax method in the view.

2 comments

This isn’t working for me. the ajax request, when viewed via the Network tab in the F12 developer tools, shows no request body (maybe a limitation of IE 11, I do see the PATCH request body in Firefox dev tools). Either way, the `delta` is not recognized / de-serialized as a controller parameter on the server.