How does mParent get set for an existing child object?

How does mParent get set for an existing child object?

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


BBM posted on Tuesday, January 16, 2007

Hi everyone and Happy New Year,

If I am instantiating an EditableRootCollection with existing EditableChild content BO, how does the mParent field in each BO get set?

If I look at example DataPortal_Fetch code for an Editable Collection (in ProjectResources for example) it just creates a DataReader and passes the reader to the 'Get' factory method of the Child BO class.

With dr

   While dr.read

          Add(ChildBOClass.GetEditableChild(dr)

   End While

End With

Now if I highlite "Add", right click and "Go to definition", VS points me to the .Net Collection(of T).Add method.

If I search CSLA for where SetParent( ) is called (or where mParent is set), I can only find it in one place, an override method for InsertItem(int, T) in BusinessListBase.

The only thing I can think of is that Collection(of T).Add internally uses the InsertItem() method to actually add the object to the end of the collection.  Since CSLA overrides InsertItem to update mParent, it gets updated as a part of the "standard" Add method call.

Have I completely missed something here or is this assumption correct?

Thanks.

BBM

RockfordLhotka replied on Wednesday, January 17, 2007

You are correct, since CSLA .NET overrides InsertItem(), it gets notified when the child (any child) is added to the collection, so it can call SetParent() at that time.

BBM replied on Wednesday, January 17, 2007

Thanks Rocky.

But how did you know that Collection(of T).Add uses InsertItem?  I couldn't find that documented anyplace.

BBM

Copyright (c) Marimer LLC