I get a simple DTO entity A loaded into my upshot viewmodel which is happily viewable via Knockoutjs.
My DTO A contains a List entities. So I can foreach over the elements inside A.
again:
class A
{
someprop;
List<B> childB;
}
Class B
{
somepropB;
}
So far so good. I can iterated over the data with no problem. But if I change "someprop" inside an instance of A and SaveAll the server will not respond at all. The updateData controlle method is not even invoked. If I clear the childB.Clear() before transmitting it to the client, all is fine.
It seems the upshot is not able to update entities with collections?
There is a bit of work to do if you want such a scenario to work. Upshot only turns the parent entities in observable items. So only the javascript representation of class A is a knockout observable, the javascript representation of class B is not. Therefore Upshot is not aware of any changes in associated objects.
The solution is to map the entities manually. To make my life easier, I've used code from my 'DeliveryTracker' sample application in the code snippets below. In my blog article you can see an example of manual mapping: http://bartjolling.blogspot.com/2012/04/building-single-page-apps-with-aspnet.html so my examples below are working on the 'delivery' and 'customer' objects.
The server-side domain model
The data service controller
The data service controller exposes the data conforming to OData standards on "http://localhost:[yourport]/api/dataservice/GetCustomers". In order to be able to update both customers and deliveries you need to define an UpdateCustomer AND UpdateDelivery function
Client-side domain model
Add a new javascript file containing your client-side model. Here I'm explicitly turning every property into an knockout observable. The key for solving your problem is the line inside the constructor of the Customer object where I'm mapping the incoming deliveries into an observable array
The View
In the index.cshtml you initialize Upshot, specify custom client mapping and bind the viewmodel
The Results
When navigating to the index page, the list of customers and related deliveries will be loaded asynchronously. All the deliveries are grouped by customer and are pre-fixed with a checkbox that is bound to the 'IsDelivered' property of a delivery. The customer's name is editable too since it's bound to an INPUT element
I don't have enough reputation to post a screenshot so you will have to do without one
When checking or unchecking the IsDelivered checkbox now, Upshot will detect the change and post it to the DataService Controller
When modifying the customer's name, Upshot will submit the changes when the input box loses focus
So if you follow above procedure, Upshot will both update parent and child entities for you.