Saved event not firing for child objects

Saved event not firing for child objects

Old forum URL: forums.lhotka.net/forums/t/8034.aspx


MikeW posted on Monday, November 23, 2009

I have a class which inherits from BusinessBase . The constructor for this class includes a call to MarkAsChild( ).

I am attempting to perform some post-save logic by handling the Saved event:

Protected Sub OnObjectSaved(ByVal sender As Object, ByVal e As Csla.Core.SavedEventArgs) Handles Me.Saved

This event handler is never executing. I have found that this never executes for child objects. Is this by design? Is there another way to accomplish the same thing? Thanks.


Jav replied on Monday, November 23, 2009

Only Root objects have a Save method, all child objects are "saved" through the Root. That is probebly the reason why the OnObjectSaved event is not called on a child.

Javed

MikeW replied on Monday, November 23, 2009

I see, but is anyone aware of any other way to include post-save processing for child objects that occurs on the client side of the DP functions?

That is, I cannot use Child_Insert, Child_Update, etc. because this processing may occur on the server side of the DP call.

RockfordLhotka replied on Monday, November 23, 2009

You want this code to run on the client?

The only way I can see is to override Save() in the root class and have it recurse through the object graph, calling some post-processing method on each object. Or use a cascading method pattern like CSLA does with IsDirty, etc.

In any case, the trick is the override of Save(), and to do your client-side work after you call base.Save().

RockfordLhotka replied on Monday, November 23, 2009

Oh, and make sure you use the result of the base.Save() call, because that'll be a different object graph than the one your override is living inside.

Copyright (c) Marimer LLC