Automatically creating a child BO


Author
Message
fseider
fseider
StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)
Group: Forum Members
Posts: 3, Visits: 3
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!

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search