Arranging ER objects hierarchically.

Arranging ER objects hierarchically.

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


markell posted on Friday, February 20, 2009

Hi.
I have ER objects, which I would like to present hierarchically by means of Folder ER objects. The objects are editable, because the user should be able to rename any object in place (exactly as in Windows Explorer).
On the other hand, the objects are root objects.
I have browsed the forum looking for proposals on how to implement it. Unfortunately, I have only discovered, that:
In short, I do not see any way out, except keep the object references in bare members, avoiding the Field Manager and implement the logic from scratch. Which brings me to another question - can I use ERLB to keep the Folder children (yes, they are children, but not in the CSLA sense of the word)?

Thanks.

markell replied on Sunday, March 01, 2009

Bump, bump, bump....

markell replied on Sunday, March 08, 2009

Anyone?

Ash002 replied on Sunday, March 08, 2009

Hi, why are these ER objects instead of EC/ECL? Presumming you wish to save one at a time? Cloning the object to be saved would include all its children, so thats no good. Is just assigning its data into a saver BO an option?

markell replied on Sunday, March 15, 2009

I am sorry, I did not understand your statement.
ER is an editable root object, they are saved one at a time.
EC is an editable child object, they are saved all at once.
My Folders are ERs, because they are saved one at a time.

I am sorry, I do not seem to grasp your idea. Can you explain it?
Thanks.

Ash002 replied on Sunday, March 15, 2009

As I read your problem, saving the ER will save all BO properties of the ER. Saving one would save the BO and its children, and their children's children. Even if a BO is not marked as child, it is still caught by the serialisation.

Suggesting do the display as databound EC. To save, copy the changed Folder EC's contents (only those to be saved, and clones of any BO properties) to a new Folder ER (or FolderUpdater ER containing a new Folder EC, Folders BLB, hence more Folder EC), and save the new ER. When save is successful, mark the databound ECs as clean.

The principle being to use ECs as normal for display, but for the blasphemous function of saving only a portion of the data graph, create new objects and copy in the data to be saved, then mark the bound objects as clean. Any properties which are BOs (other than Folder, eg FolderSecurity) could be cloned.


markell replied on Monday, March 16, 2009

Well, I must have explained a bit more about how I am doing it right now.
Of course, I am aware of the serialization process, however, the children collection is marked with the NonSerialized attribute. When a Folder BO is saved, the new instance before being returned to the user is passed the children from the old one, like this:

[NonSerialized]
private FolderList m_children;

protected override void OnSaved(Folder newObject, Exception e, object userState)
{
   if (newObject != null)
   {
       newObject.m_children = m_children;
       if (IsNew && IsParentLoaded && Parent.AreChildrenLoaded)
       {
             Parent.Children.Add(newObject);
       }
   }
   base.OnSaved(newObject, e, userState);
}

Where Folder.Parent shadows the BusinessBase<T>.Parent property.


alef replied on Thursday, January 28, 2010

Is it possible to provide a full working example?

markell replied on Friday, January 29, 2010

@Alef, it is not that easy. We do not have a small standalone solution. Instead, we have developed an extra level on top of the CSLA framework. This layer supports folder like parent-children relationship as well as other things, that we needed, like in-place saving of entities (the idea of returning a new object on each save does not suit very well our needs) or supporting multiple data portal proxies. To do these and more we had to make minor changes to the CSLA code.

Unfortunately, I do not have the time to create a simply concise example - my time does not belong to me :-(.

ajj3085 replied on Sunday, March 08, 2009

You could attempt to implement a Composite pattern on your BB subclass.  I'm not sure you can use the newer FieldManager to manage the child collection though.  It's a fair amount of work. 

I'm not sure how you'd implement this though having each instance as a root.  Perhaps the entire tree should be read-only objects ,and when the tree value is changed, you can execute a command to hit the db and update, and then update the read-only instance.  That might be the best way to go..

markell replied on Sunday, March 15, 2009

Hi.
Can you elaborate a bit on this Composite pattern thing? I know what the patter is, but I find it hard to see how it is applicable to my situation.

As I have mentioned, the user should be able to rename the folders in place, which is done through the WPF data binding - binding the Folder.Name property to the Text property of the TextBox, which becomes visible when the user clicks the tree item. Your suggestion implies that I should maintain two sets of BOs - ROC FolderInfo and ER Folder in the same context (unlike the ProjectTracker's RoleInfo and Role BOs, which were used in different contexts).

It seems to me that this is not a very good solution. Is there a working example of this approach?
Thanks.

Copyright (c) Marimer LLC