Sending an entity type with children to an OData service (MVC Web Api)

I searched for the answers to the following questions, but haven’t found them yet.

  • Does the OData standard support the execution of a POST request containing an entity object with child entity objects?
  • If so, does ASP.NET MVC Web Api OData framework ( EntitySetController) support this out of the box?

The scenario that I mean looks something like this: You have an object Parentthat contains several objects Child. Could you do a POST with such a body?

{ "Property1" : "Property value", "Property2" : 100 
     "Children" : [
          { "ChildProperty" : "Some value" },
          { "ChildProperty" : "Some other value" },
          { "ChildProperty" : "Some third value" }
     ]
}

Also, if later I would like to add another child to the object Parentthrough POSTing of one child, is there a standardized way to combine them? Sort of

 { "ChildProperty" : "Fourth child property val", "Parent" : 321 }

where '321' is the parent id?

!

+4
1

, OData , API OData. OData deep insert. .

,

1) . json :

{
    ‘Property1’: 42,
    ‘Property2’: ‘Contoso’,
    ‘Children’: [
    {
        ‘ChildProperty’: 1,
        ……….
    },
    {
        ‘ChildProperty’: 2,
        ……….
    }]
}

2) , . OData . :

{
    ‘Property1’: 42,
    ‘Property2’: ‘Contoso’,
    ‘Children@odata.bind’: [
        "http://localhost/Children(1)",
        "http://localhost/Children(2)",
    ]
}

Web API OData ( ). Parent Children.

:

1) ~/Parents(321)/Children URL

2) ~/Children, POST ID URL ~/Parents(321)/$links/Children.

+6

All Articles