Simple questions. In Expert VB 2008, Rockford shows this method to update child objects:
But the sample project shows:
DataPortal.UpdateChild(ReadProperty(Of ProjectResources)(ResourcesProperty), Me)
I assume that the fieldmanager updates everything whereas the dataportal updates a specific collection. Is my assumption correct and is there a difference between the two calls?
My other question is do I need to include this in both the DataPortal_Insert and DataPortal_Update methods? My understanding of the updatechild call is that it performs Insert, Update, and Delete on all of the appropriate child objects. If that is true is there a reason for calling the updatechild again on the DataPortal_Update method?
And finally, if a child object contains a businesslistbase, does that child object need to call the dataportal.updatechild or does the first updatechild go to grandchildren as well?
The FieldManager method is just a helper that finds all the child objects and calls UpdateChild() on them. If you care about the order of child updates, you can't use the FieldManager approach, and you need to call DataPortal directly.
You do need to put this in DP_Insert and DP_Update. If you only put it in DP_Insert, for example, then the children will be inserted, but they'd never be updated.
The calls do not cascade through the object graph. In other words, when the parent updates its children, that does not automatically update the grandchildren.
The reason it doesn't automatically cascade is primarily due to backward compatibility. If I forced everyone to use managed backing fields for child references then it could be automatic, but that'd be a big breaking change from older code.
And if it was automatic, then I'd need to devise some scheme by which you could control the order of child updates - because sometimes order matters.
Copyright (c) Marimer LLC