Using Delta <T> with Complex Objects

Can Delta <T> be used with complex graphs of objects, and not with individual objects? I tried to use it without success, and I wonder if I am missing something or if the functionality is simply not supported.

For example, here is the 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 is the OData model building:

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

For my controller's POST method, I can use this JSON and it will deserialize perfectly:

{
  "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 the Address property, with a value of zero for City and PostCode and "Another Street" for Street. That seems right to me.

delta.Patch(person), person, , , Street .

- , Delta <T> ?

+4
1

. , OData, .

-API ( PATCH ) .

+2

All Articles