I have an ASP.NET WebApi OData service, and I am trying to consume it from JavaScript using JayData. My model is as follows:
class Parent {
ICollection<Child> Children;
}
class Child {
ICollection<Parent> Parents;
}
I'm trying to add a new parent entity with a new child entity using JayData context, something like:
var child = new db.Children.Child({Parents: []});
var parent = new db.Parents.Parent({Children: [child]});
db.Parents.add(parent);
db.saveChanges();
As a result, JayData sends a batch request to the OData service containing 2 post requests: one for the child and another for the parent, where the child is given Content-ID = 1, and the parent entity is serialized to JSON as:
{'Children': [{'__metadata': {'uri': '$1'}}]}
On the server side, the CreateEntity method of both Parent and Child EntitySetControllers gets executed, but the Parent argument has an empty collection of Children, i.e. it ignores the Content-ID reference to the new Child entity from the request.
Is there a convenient way to make it work in ASP.NET OData, or do I have to parse the Parent's JSON from the request and check whether such references exist by hand?