4

Can Delta<T> be used with complex object graphs, rather than single objects? I have tried without success to use it and am wondering if I'm missing something or if the functionality simply is not supported.

For example, here's a model:

public class Person {
  public int Id { get;set; }
  public string Name { get;s set; }
  public Address Address { get; set; }
}

public class Address {
  public string Street { get; set; }
  public string City { get; set; }
  public string PostCode { get; set; }
}

And here's the OData model building:

var builder = new ODataConventionModelBuilder();
builder.ComplexType<Address>();
builder.EntitySet<Person>("Person");

For the POST method of my controller, I can use this JSON and it will be deserialised fine:

{
  "Name": "Mr Smith",
  "Address": {
    "Street": "Some Street",
    "City": "Some City",
    "PostCode": "Some PostCode"
  }
}

However, problems arise when I use PATCH. If I send this:

{ 
  "Name": "Mr Doe",
  "Address": {
    "Street": "Another Street"
  }
}

And my controller method signature looks like this:

public IHttpActionResult Patch([FromODataUri] key, Delta<Person> delta) { ... }

Then the delta will contain an Address property, with null for City and PostCode and "Another Street" for Street. This seems to be correct to me.

When I then use delta.Patch(person) to apply the changes to the person object it copies this address wholesale over to the person, rather than just updating the Street property of the address.

Am I missing something, or is patching of complex type properties not supported by Delta<T>?

Mark Watts
  • 724
  • 7
  • 15

1 Answers1

2

That's the current behavior. Complex type property, one of the structural property in OData, is treated as an unit when updating an entity.

However, Web API has the issue (Support PATCH to a complex type) to track this problem.

Sam Xu
  • 3,264
  • 1
  • 12
  • 17