Breeze.js - How do I create/add child objects to a parent that I am also creating? -


given following ef model:

public class order {   public int orderid { get; set; }   public string customername { get; set; }   public virtual icollection<orderdetail> orderdetails { get; set; }   ... }  // orderdetail has composite key of orderid , productid public class orderdetail {   public int orderid { get; set; }   public int productid { get; set; }   public int quantity { get; set; }   ... } 

in mvc4 web app (using hottowel spa template - durandal, breeze.js, knockout, etc.), have created view creating new order , addding/removing orderdetail items.

in datacontext.js, have following:

var createorder = function() {   return manager.createentity('order'); }; 

in viewmodel orderadd.js, calling createorder:

order = ko.observable();  activate = function() {   initlookups();   order(datacontext.createorder()); } 

question: how create/add new orderdetail items order object , save entire new order object in db?

do same way creating order, add navigation property order order detail.

var createorderdetail = function() {     return manager.createentity('orderdetail'); };  var order = ko.observable();  activate = function() {     initlookups();     order(datacontext.createorder());     var orderdetail = datacontext.createorderdetail();     orderdetail.order(order()); } 

another option set order when creating entity orderdetail have found there slight timing issue knockout gets mad while entity create , not of values have been assigned required in view. example of way -

var createorderdetail = function(order) {     return manager.createentity('orderdetail', { order: order }); };  var order = ko.observable();  activate = function() {     initlookups();     order(datacontext.createorder());     var orderdetail = datacontext.createorderdetail(order()); } 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -