(Order and OrderItem generated by SubSonic).
Order order = new Order();
//populate order details.
OrderItem item = new OrderItem();
//populate orderItem details.
item.Order = order; //THIS LINE SETS THE PARENT OBJECT TO ABOVE ORDER
Just remember to wrap up in a transaction and call the save methods to commit this info to your database. You will have add a reference to the System.Transactions namespace in your project and then reference in your class.
e.g
using (TransactionScope scope = new TransactionScope())
{
try
{
Order order = new Order();
//populate order details.
order.Save(); //Commit to DB
OrderItem item = new OrderItem();
//populate orderItem details.
item.Order = order; //THIS LINE SETS THE PARENT OBJECT TO ABOVE ORDER
item.Save(); //Commit to DB
//complete you transaction
scope.Complete();
}
catch (System.Data.SqlClient.SqlException ex)
{
throw ex;
}
}
It's true that if your primary key is just a identity value auto incremented, you would have no real use for ON UPDATE CASCADE.
However, let's say that your primary key is a 10 digit UPC bar code and because of expansion, you need to change it to a 13-digit UPC bar code. In that case, ON UPDATE CASCADE would allow you to change the primary key value and any tables that have foreign key references to the value will be changed accordingly.
In reference to #4, if you change the child ID to something that doesn't exist in the parent table (and you have referential integrity), you should get a foreign key error.
Best Answer
Subsonic code generation will read the foreign key relationships in the tables and create the required helper methods in the table classes. The Northwind Product class has a PrimaryKey relationship to the OrderDetail class. Subsonic generates the method
public Northwind.OrderDetailCollection OrderDetails()
to get the OrderDetail rows as an OrderDetailCollection. This is a BindingList that you can change as needed, and call SaveAll() to save the list. There is no deep saving, so saving the Product won't save related OrderDetail rows.