How to synchronize the edit level for a private BusinessBase derived child object?

How to synchronize the edit level for a private BusinessBase derived child object?

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


stefan posted on Tuesday, September 23, 2008

My customer class is holding all the contact data in a private contactdata member variable.
I do not want to expose the contactdata object. It should take care of the data passed to it,
provide the undo functionality, raise the appropriate events when data changes and handle the
ChildDataPortal functionality...

My customer class wrappes all the contactdata properties and has the associated validation rules,
which is the main reason for this architecture: I want to have the authorization subsystem associated to the customer, not to the contactdata!

PropertyHasChanged for these properties is triggered from the contactdata child object.
The customer subscribes to these notifications over the new ChildChanged event,
and would trigger his own PropertyHasChanged event respectively for databinding to work...
(That is at least what I plan for.)

The problem is, as often, WinForms databinding:
Despite not having a bindingsource for my contactdata childobject,
I somehow need to keep the edit level synchronized with the customer object in the object itself!

How can I keep the edit level of a non public child business object in sync with its parent edit level, so that undo works as well for this (private) child?.

Stefan

RockfordLhotka replied on Tuesday, September 23, 2008

You can implement ContactData in two ways

  1. As a plain .NET object - in which case n-level undo will simply serialize/deserialize the object as a blob. This can work very well, as long as you refresh the instance reference and event hooks when undo is complete (there's a method you override to be notified when an undo operation is complete). There is no edit level in this case - snapshots of the "child" object are automatically maintained/restored.
  2. As a BusinessBase<T> object - in which case you should maintain a reference using a managed backing field in 3.5+. In this case the edit level is automatically maintained by the framework and you shouldn't have to worry about it.

 

stefan replied on Wednesday, September 24, 2008

Thanks for your suggestions.

I would like to implement it  following alternative 2.
But, my Contactdata needs to be updated (inserted) prior to anything else (providing the primary key),
so I cannot call FieldManager.UpdateChildren (which I do for the remaining child objects).

Is there a way to exclude a specific child from the UpdateChildren process,
or can we interfere somehow manually?


Stefan

RockfordLhotka replied on Wednesday, September 24, 2008

Nothing forces you to use UpdateChildren() – it is a helper method to make things simpler, but it is not required.

 

Your parent object could just do this:

 

Protected Overrides Sub DataPortal_Insert()

 

  Using …ConnectionManager…

    DataPortal.UpdateChild<ContactData>(ReadProperty(ContactDataProperty))

    ‘ repeat for each child

  End Using

 

End Sub

 

That’s all UpdateChildren() does – simply loops through all your child fields and calls the data portal. If you do it manually, it is a little more work, but then you control the order of processing.

 

Rocky

 

 

 

From: stefan [mailto:cslanet@lhotka.net]
Sent: Wednesday, September 24, 2008 7:08 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] How to synchronize the edit level for a private BusinessBase derived child object?

 

Thanks for your suggestions.

I would like to implement it  following alternative 2.
But, my Contactdata needs to be updated (inserted) prior to anything else (providing the primary key),
so I cannot call FieldManager.UpdateChildren (which I do for the remaining child objects).

Is there a way to exclude a specific child from the UpdateChildren process,
or can we interfere somehow manually?


Stefan


Copyright (c) Marimer LLC