Cloning issue?

Cloning issue?

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


ajj3085 posted on Thursday, September 27, 2007

Hi,

I have an odd object model, admittedly.

I have a line item, called Simple.  There's also a LineItemList which contains anything that implements ILineItem.

I have a GroupItem, which has an Items collection, which contains GroupSubItems.  A GroupSubItem is a composite (wrapper) around a Simple line item.

Everything is great, until I go to clone.  Actually, its great until after I clone a second time it seems.

Simple has its BusinessBase.Parent item set, which it needs to function.  After Saving the LineItemList (which is a child of another Document object), a subsequent Clone of the Document results in the Simple item which is wrapped losing its reference to Parent. 

Now, it seems that this should not be happening, but it is.  I've fixed it for now by adding some code in the GroupSubItem's OnDeserialized method, but it seems odd that its losing this reference anyway. 

I'm using Csla 3.0.2 test 4.

Thanks
Andy

RockfordLhotka replied on Friday, September 28, 2007

You mean the parent field managed by BB is losing its value? That value is lost during deserialization, but the OnDeserialized() code in BLB loops through and calls SetParent() to reset the value - so by the time deserialization is complete it should have been reset.

But if the parent is not a BLB, then this is not automatic, and you'd have to write code in the parent's OnDeserialized() method to call SetParent().

ajj3085 replied on Friday, September 28, 2007

Yes, the Parent from BB was affected.  I forgot that Csla was handling the resetting of that for me... for some reason I thought that the Serializer did that.

Glad to know this was expected, and I implemented the correct solution.

Thanks!
Andy

RockfordLhotka replied on Friday, September 28, 2007

That’s something I’d like to implement at some point: a “child manager” you can use when one object is a child of another object that isn’t a list. This “child manager” would do all the things BLB does to manage the child’s lifetime, including calling SetParent().

 

Beyond that, what I envision is more of a “children manager”, because that would allow me to automatically handle IsValid and IsDirty (so you don’t need to do the overrides), manage the Parent property and so forth.

 

But I just haven’t had time to dig into this enough yet…

 

Rocky

Copyright (c) Marimer LLC