Visual Studio supports the generation of data service clients (Service references) for OData services. A data service client is a .NET class that contains methods for accessing the OData service and gets generated based on the metadata provided by the OData service. The client acts as a proxy and translates the method calls into HTTP requests.

Mike Wasson describes in his blog post Calling an OData Service From a .NET Client (C#) how to generate and use such a data service client.

When updating objects using the data service client the client by default sends a HTTP MERGE request after calling container.SaveChanges().

If desired the default behaviour can be easily changed. To do PUT or PATCH requests instead of MERGE the SaveChangesDefaultOptions have to be changed as shown below.

PUT
container.SaveChangesDefaultOptions = System.Data.Services.Client.SaveChangesOptions.ReplaceOnUpdate;

PATCH
container.SaveChangesDefaultOptions = System.Data.Services.Client.SaveChangesOptions.PatchOnUpdate;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.