Insert/update/delete are far easier than Fetch.
The same techniques used in my books work for insert/update. Your child collections/objects will all accept a reference to the root (and any other foreign-key-containing parent) as parameters to their internal/Friend Insert() and Update() methods. Each child is responsible for inserting/updating/deleting itself.
In other words, the root object calls an internal/Friend Update() method on each child collection in the DataPortal_Insert/Update methods:
_childCollection.Update(Me)
Notice that a reference to the root object is passed to the child collection. The child collection loops through its children (and DeletedList) calling the appropriate internal/Friend Insert/Update/DeleteSelf methods on each child:
Friend Sub Update(ByVal parent As MyRoot)
For Each child As MyChild In Me
If child.IsNew Then
child.Insert(parent)
Else
child.Update(parent)
End If
Next
'...
End Sub
Each child object inserts or updates (or deletes - remember to loop through DeletedList and call child.DeleteSelf()) - itself, and then cascades the call to its child collection:
_grandchildCollection.Update(parent, Me)
Notice how it passes both the root parent and itself as a parameter. I'm assuming that both objects now provide foreign key values to the grandchildren. The grandchild collection and grandchildren themselves merely use the same pattern as I've already shown.
As far as transactions, there are two scenarios:
Copyright (c) Marimer LLC