Confusion regarding EditableRootParent template

Confusion regarding EditableRootParent template

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


pegesaka posted on Wednesday, January 16, 2013

Can someone please give me some advice on the correct template to use. I have CSLA 4.3.12 and using the templates that came in that source.

I need to have an EditableRootList have some properties about the list it contains. According to the 4.3 literature, this list should be "parented" by an editable parent that can have managed properties. The editable children of the editable List already have an EditableChildList property that loads fine. (Havent tried saving or undo-ing, but assuming it will work).

My question is, should the root list's parent be an EditableRoot or an EditableRootParent? I notice there was a thread title "Lists and Root/Child Objects" back in 2006, which gave some reasoning in what to use. But it was referring to code that didnt exist in my templates and consider that CSLA has moved on a bit since 'O6.

EditableRootParent already contains a list property -

    // example with Editable Child list
    public static readonly PropertyInfo<EditableChildList> ChildListProperty = RegisterProperty<EditableChildList>(p => p.ChildList, "Child list", RelationshipTypes.Child);
    public EditableChildList ChildList
    {
      get { return GetProperty<EditableChildList>(ChildListProperty); }
    }

which appears to be the reason for the template differentiation, but I dont understand the "Child list" parameter and cant find any doco on this method overload. Can anyone give me some clues?

But then the DataPortal code is completely different. Rather than relying on just getting the server dataportal to get the (now) child list property (as the EditableChild does for an EditableChildList), the Fetch in an EditableRootParent calls -

      LoadProperty(ChildListProperty, EditableChildList.GetEditableChildList(null));

The code I am using in my EditableChild, to get my EditableChildList, is -

      Assignments = JobAssignments.GetJobAssignments(param1, param2, ...);

ie. I am instantiating a BO using its static method to assign to a property in my EditableChild, which I considered was correct. Is it? Why wouldnt I use the same approach to set the ChildListProperty in my EditableRootParent?

Also the DataPortal Insert/Update/Delete methods call -

      FieldManager.UpdateChildren(this);

Am I meant to do this in my EditableChild to update my EditableChildList? Or can I assume that CSLA will know that it is a child list and Save it correctly?

I'm confused. Hope someone can help.

Cheers,

Perry

pegesaka replied on Wednesday, January 16, 2013

OK, been fiddling and found a few answers. The "Child List" parameter is just a friendly name for display purposes.

The LoadProperty() in the dataportal fetch is required as there is no setter in the ChildListProperty declaration, whereas I have a private set() in the parent of my child list.

But I dont get the DataPortal Insert/Update/Delete methods implementation. Is this required on all Child Lists?

Cheers,

Perry

JonnyBee replied on Sunday, January 20, 2013

Only the "root" object has DataPortal_XYZ methods.

Assuming that you use DataPortal.UpdateChild or FieldManager.UpdateChildren in your parent "parent" object the Child_XYZ methods will be called in your child editable objects. You will then NOT need to implement any Insert/Update/Delete method on the child lit objects.

Copyright (c) Marimer LLC