OData / AspNetCoreOData

ASP.NET Core OData: A server library built upon ODataLib and ASP.NET Core
Other
457 stars 158 forks source link

Related entities are not de-serialized correctly when both: deep insert entities and bind operations are present in the request #784

Open korygin opened 1 year ago

korygin commented 1 year ago

Assemblies affected Microsoft.AspNetCore.OData, Version=8.0.12.0

Describe the bug. When inserting a new entity with a POST request, related entities MAY be specified using the same representation as for an expanded navigation property or a bind operation: http://docs.oasis-open.org/odata/odata-json-format/v4.0/cs01/odata-json-format-v4.0-cs01.html#_Toc365464707. However, if both are present in the request's body, ODataEdmTypeDeserializer only de-serializes related resources represented by bind operations and ignores expanded entities.

Reproduce steps Consider the following HTTP POST request payload:

{
   "@odata.type": "#Com.Ingr.SampleApi.V1.Pipeline",
   "Name": "390207-MC4",
   "Description": null,
   "Pipes@odata.bind": [
      "Pipes('443C7C34-A96C-4499-950F-BDCF06630783')"
   ],
  "Pipes": [
   {
     "@odata.type":"#Com.Ingr.SampleApi.V1.Pipe",
     "Name":"Y0001", 
     "Description":null,
     "IsInsulated":false
    }
  ]
}

In this example, the new pipeline entity is created with 2 related pipes: the first pipe already exists and is represented by the bind operation and the second pipe should be created using deep insert operation. However, after the pipeline entity is de-serialized, its Pipes navigation property contains only one related pipe instance represented by the bind operation with just id populated. The second pipe is not present in the Pipes collection.

Data Model Because our EDM model is dynamic we use untyped data model represented by EdmEntityObject / EdmComplexObject objects. CLR types are not used.

EDM (CSDL) Model

Request/Response

Expected behavior I would expect the Pipes navigation property to contain expanded Pipe entity after de-serialization.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Please share your call stack or any error message Add any other context about the problem here.

gathogojr commented 1 year ago

@korygin Thanks for reporting the issue. I don't believe we support the both odata.bind and nested inline collection presentation for the same property. Does it work if you only have the nested inline collection?

korygin commented 1 year ago

Yes, it works unless both are specified.