Stack:
I have a master-detail scenario. In the master part, I'm editing a Order and on the details part i have the orders products. I can list all the products I have and that works great, but I now need to display the master and details.
This is my Web API method:
public Order GetSingleOrder(long orderId)
{
return DbContext.Orders
.Include("OrderedProducts")
.Include("OrderedProducts.Product")
.Include("OrderedProducts.Product.Family")
.Single(o => o.OrderId == orderId);
}
This works nice, it returns only one order with products and it's info.
But in the viewModel, I can't get this as single order, upshot datasource only provides a method called getEntities()
and can't get to it's items.
var CreateOrEditViewModel = function () {
var self = this;
self.dsOrder = upshot.dataSources.SingleOrder.refresh();
self.orders = self.dsOrder.getEntities();
self.order = self.orders()[0];
};
it appears its lazy loaded and at the time getEntities()
is called it does not have any items and self.orders()
returns a empty collecton.
Update: I need a way to get one order, bind to that order, let the user update it's fields, and save it through the datasource.
It isn't lazy loaded, but it is asynchronous. When you call upshot.dataSources.SingleOrder.refresh() you can pass in two callback functions, one for success and one for error. In the callback you will have your loaded data.