I'm using Simple.OData.Client and I would like to update certain properties of an entity.
Let's say I have following class in C#:
[DataContract(Name = "entity")]
public class MyEntity
{
[DataMember(Name = "propertyA")]
public string MyPropertyA { get; set; }
[DataMember(Name = "propertyB")]
public string MyPropertyB { get; set; }
}
I'm trying to update propertyA like this:
await _simpleOdataClient.For<MyEntity>()
.Key(key)
.Set(new MyEntity
{
MyPropertyA = "test"
})
.UpdateEntryAsync();
I took this as an example: https://github.com/object/Simple.OData.Client/wiki/Updating-entries
My problem is that sends a PUT request with propertyA=test but also propertyB=null. It tries to set null value for the property I don't want to change.
Is it possible to only update certain properties and to send HTTP PATCH in the OData request?
You should use an anonymous object for doing that or find some way to configure the client's serializer to ignore default values (e.g. null on a ref type).