All,
I'm just starting my CSLA adventure and I thought I would post this question here.
I see that the Editable Root Object has a Update Child sub with a connection as a param. How do I use this function to actually update my child record? Sorry for the newbie question.
Thank You,
Jeff
You can look at the Project Tracker example. its really good, very helpful
Ellie
Jeff,
Here is some sample code that you can examine to see how the pattern is implemented.
===========================================================================================================
<Serializable()> _
Public Class MyRootBO
Inherits MyBusinessBase(Of MyRootBO)
'private fields here
Protected mChildColl As ChildColl
Protected Overrides Sub DataPortal_Update()
Dim tr As IDbTransaction = Nothing
Try
tr = BeginTransaction()
DoUpdate(tr)
EndTransaction(tr)
Catch ex As Exception
RollbackTransaction(tr)
Throw
End Try
End Sub
Protected Overridable Sub DoUpdate(ByVal tr As IDbTransaction)
Dim user As MyUser
user = DirectCast(Thread.CurrentPrincipal, MyUser)
UpdateData(tr, user)
PostUpdateData(tr, user)
UpdateChildren(tr)
End Sub
Protected Overridable Sub UpdateData(ByVal tr As IDbTransaction, ByVal user As MyUser)
DAL.ExecuteNonQuery(tr, CommandType.Text, GetSQL.Update(..., user.Userkey))
End Sub
Protected Overridable Sub UpdateChildren(ByVal tr As IDbTransaction)
ChildColl.Update(tr, DirectCast(Me, MyRootBO))
End Sub
===========================================================================================================
'childColl BO sample code
Protected Friend Overridable Sub Update(ByVal tr As IDbTransaction, ByVal MyRootBO As MyRootBO)
RaiseListChangedEvents = False
For Each child As MyChild In DeletedList
child.Update(tr, Item)
Next
DeletedList.Clear()
For Each child As MyChild In Me
child.Update(tr, Item)
Next
RaiseListChangedEvents = True
End Sub
===========================================================================================================
'child BO sample code
Protected Friend Overridable Sub Update(ByVal tr As IDbTransaction, ByVal MyRootBO As MyRootBO)
If Not Me.IsDirty Then
Exit Sub
End If
Dim user As MyUser
user = DirectCast(Thread.CurrentPrincipal, MyUser)
If Me.IsDeleted Then
If Not Me.IsNew Then
DeleteChildren(tr)
DAL.ExecuteNonQuery(tr, CommandType.Text, GetChildSQL.Delete(mKey))
PostDeleteData(tr, user)
End If
MarkNew()
Else
If Me.IsNew Then
InsertData(tr, MyRootBO, user)
PostInsertData(tr, user)
Else
UpdateData(tr, user)
PostUpdateData(tr, user)
End If
UpdateChildren(tr)
MarkOld()
End If
End Sub
Protected Overridable Sub DeleteChildren(ByVal tr As IDbTransaction)
'marker method that can be overridden in child class
End Sub
Protected Overridable Sub InsertData(ByVal tr As IDbTransaction, ByVal MyRootBO As MyRootBO, ByVal user As MyUser)
DAL.ExecuteNonQuery(tr, CommandType.Text, GetChildSQL..Insert(MyRootBO.Key,..., user.Userkey))
End Sub
Protected Overridable Sub UpdateData(ByVal tr As IDbTransaction, ByVal user As MyUser)
DAL.ExecuteNonQuery(tr, CommandType.Text, GetChildSQL.Update(..., user.Userkey))
End Sub
Protected Overridable Sub UpdateChildren(ByVal tr As IDbTransaction)
'marker method that can be overridden in child class
End Sub
Copyright (c) Marimer LLC