Shadow Save Methods?

Posts   
 
    
tmaddox
User
Posts: 9
Joined: 02-Jul-2007
# Posted on: 11-Oct-2007 20:26:39   

We have tried to Shadow the 4 Save Methods in one of our Entity Classes, so that we can implement a MarkForDeletion property. This would allow us to only delete the entity from the database if the save method has been called (for cancelling/reset purposes).

For some reason these Save methods never seem to be hit. Why is this not working.

We are using the latest version of LLBLGen, using a Self Servicing template.

To save our entities we are using ParentEntityName.Save(True), which should then trickle down to all the save methods of the children. It is the child entity that has the shadowed saves.

        Public Shadows Function Save() As Boolean
            If Me.ToBeDeleted Then
                Me.Delete()
            Else
                MyBase.Save()
            End If
        End Function

        Public Shadows Function Save(ByVal recurse As Boolean) As Boolean
            If Me.ToBeDeleted Then
                Me.Delete()
            Else
                MyBase.Save(recurse)
            End If
        End Function

        Public Shadows Function Save(ByVal updateRestriction As SD.LLBLGen.Pro.ORMSupportClasses.IPredicate) As Boolean
            If Me.ToBeDeleted Then
                Me.Delete()
            Else
                MyBase.Save(updateRestriction)
            End If
        End Function

        Public Shadows Function Save(ByVal updateRestriction As SD.LLBLGen.Pro.ORMSupportClasses.IPredicate, ByVal recurse As Boolean) As Boolean
            If Me.ToBeDeleted Then
                Me.Delete()
            Else
                MyBase.Save(updateRestriction, recurse)
            End If
        End Function
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 11-Oct-2007 20:45:22   

All save methods end up in the method: public virtual bool Save(IPredicate updateRestriction, bool recurse)

So you should just OVERRIDE that save method and call the base variant. That's how virtual (overridable) methods work simple_smile

So do: Public Overrides Overloads Function Save(ByVal updateRestriction As SD.LLBLGen.Pro.ORMSupportClasses.IPredicate, ByVal recurse As Boolean) As Boolean If Me.ToBeDeleted Then Me.Delete() Else MyBase.Save(updateRestriction, recurse) End If End Function

Although I wouldn't really do it like this. If you want to track work, like which entities to delete and which ones to save, please use a UnitOfWork object to add the entities to delete/save, and commit the unitofwork in one go

Frans Bouma | Lead developer LLBLGen Pro