Cascade Operations

Composite relationships are cascaded. Cascade operations allow a single synchronization to execute a chain of related CUD operations. Multi-level insert is a special case for cascade operations. It allows parent and children objects to be created in one round without having to synchronize multiple times.

Refer to Unwired WorkSpace documentation (Relationship Guidelines and Multi-level insert operations) for information about defining relationships that support cascading (composite) operations.

Consider creating a Customer and a new SalesOrder at the same time on the client side, where the SalesOrder has a reference to the new Customer identifier. The following example demonstrates a multilevel insert:

Customer customer = new Customer();
customer.Fname = “firstName”;
customer.Lname = “lastName”;
customer.Phone = “777-8888”;
customer.Save();
SalesOrder order = new SalesOrder();
order.Customer = customer;
order.Order_date = DateTime.Now;
order.Region = "Eastern";
order.Sales_rep = 102;
customer.Orders.Add(order);
//Only the parent MBO needs to call Save()
customer.Save();
//Must submit parent
customer.SubmitPending();

To insert an order for an existing customer, first find the customer, then create a sales order with the customer ID retrieved:

Customer customer = Customer.FindByPrimaryKey(102);
SalesOrder order = new SalesOrder();
order.Customer = customer;
order.Order_date = DateTime.UtcNow;
order.Region = "Eastern";
order.Sales_rep = 102;
customer.Orders.Add(order);
order.Save();
customer.SubmitPending();

To update MBOs in composite relationships, perform updates on every MBO to change and call SubmitPending on the parent MBO:

Customer cust = Customer.FindByPrimaryKey(101);
Sybase.Collections.GenericList<SalesOrder> orders = cust.Orders;
SalesOrder order = orders[0];
order.Order_date = DateTime.Now;
order.Save();
cust.SubmitPending();

To delete a single child in a composite relationship, call the child's Delete method, and the parent MBO's SubmitPending.

Customer cust = Customer.FindByPrimaryKey(101);
Sybase.Collections.GenericList<SalesOrder> orders = cust.Orders;
SalesOrder order = orders[0];
order.Delete();
cust.SubmitPending();

To delete all MBOs in a composite relationship, call Delete and SubmitPending on the parent MBO:

Customer cust = Customer.FindByPrimaryKey(101);
cust.Delete();
cust.SubmitPending();
Note: For non-composite relationships, SubmitPending must be called on each and every MBO.

See the Sybase Unwired Platform online documentation for specific multilevel insert requirements.