I need to add a Child BO whenever I add a new Parent BO. I have the proper parent/parent relationship setup, and can add the child BO manually within a form when testing. (Parent = LocationBO, Child = PremisesBO)The problem is the best place to do this, as in what Parent BO event or some other place? I tried the AfterAddNew event, but the Parent PK is equal to a -1 which I suspect is because the Parent has yet to be saved, so I can't assign the proper PK to the Child BO FK If I put the following code in the AfterSave, it works fine:
Private Sub LocationsBO_AfterSave(ByVal e As MicroFour.StrataFrame.Data.AfterSaveUndoEventArgs) Handles Me.AfterSave
Dim pBO As New PremisesBO
pBO.Add()
pBO.Name = "Premise"
pBO.LocationsID = Me.LocationsID
Try
pBO.Save()
Catch ex As Exception
End Try
End Sub
The problem is that this event is also triggered when I delete my BO on a form:
Private Sub btnLocationBO1Delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLocationBO1Delete.Click
LocationBO1.DeleteCurrentRow()
LocationBO1.Save()
End Sub
So, what is the obvious approach I am overlooking? I only need to create my ChildBO whenever I create my Parent. The database handles the Child delete just fine with a Parent delete via a cascade.
Thanks in advance!