OData / WebApi

OData Web API: A server library built upon ODataLib and WebApi
https://docs.microsoft.com/odata
Other
855 stars 473 forks source link

Patch does not update navigation property #2430

Open indeecev opened 3 years ago

indeecev commented 3 years ago

Patch does not update navigation property. Does it works? How can I get it to work? Thanks.

Assemblies affected

OData WebApi lib 7.5.6

Reproduce steps

Two etity sets:

class Foo {
  string Name { get; set; }
}

class Bar {
  string Name { get; set; }
  Foo FooRef { get; set; }
}

Bar controller: class Bar : ODataController { [HttpPatch] public ActionResult Patch(int key, Delta delta) {

} } Create Bar instance with id = 1: ``` POST /odata/Bars HTTP/1.1 Host: localhost Content-Type: application/json Content-Length: 35 { "Name" : "BarInstance" } ``` Create Foo instance, with id = 1: ``` POST /odata/Foos HTTP/1.1 Host: localhost Content-Type: application/json Content-Length: 35 { "Name" : "FooInstance" } ``` Update Bar with id = 1. ``` PATCH /odata/Bars(1) HTTP/1.1 Host: localhost Content-Type: application/json Content-Length: 64 { "FooRef@odata.bind" : "http://localhost/odata/Foos(1)" } ``` Also, I tried odata v4.01 syntax, with "@id", but it does not work too. It even cannot parse this syntax. Delta is null. Get Bar with id = 1 GET /odata/Bars(1)?$expand=FooRef HTTP/1.1 Host: localhost Content-Type: application/json ### Expected result { "Id": 1 "Name": "BarInstance", "FooRef": { "Id": 1 "Name": "FooInstance", } } ### Actual result { "Id": 1 "Name": "BarInstance", "FooRef": null } ### Additional detail Delta does not contain "FooRef" as changed property. I found this [code](https://github.com/OData/WebApi/blob/4ff7ca8e8a46bc00d639480149df3fb1d7e50ca8/src/Microsoft.AspNet.OData.Shared/Formatter/Deserialization/ODataResourceDeserializer.cs#L320) Does it mean, that entity reference links do not supported?
marabooy commented 3 years ago

@indeecev This is know feature gap within WebApi which we are currently working on adding support.