The comments in IEditableBusinessObject are correct in 2.1.4, and I think in 2.1.3 - I don't remember fixing them, but they are correct in the current code anyway.
Yes, any parent may call SetParent() on its immediate child objects. This must be done under a couple conditions:
I think you are on your own in that case. The Parent property
implemented in BusinessBase is read-only, and the field is private. The idea is
that it is the parent’s responsibility to handle the hookup –
primarily because at that time the parent is almost certainly also performing
an event hookup, and because the value must be restored after deserialization,
and only the parent can do that.
If you want to add a PendingParent property, there’s no
reason you couldn’t do that – but the only reliable parent value
over the entirely life of your object is the one managed by the actual parent.
Rocky
From: Jimbo
[mailto:cslanet@lhotka.net]
Sent: Friday, March 02, 2007 2:02 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] IEditableBusinessObject xml doc error
I am talking about the ctor for the "pending"
child being able to set its "proposed' parent reference. ie the parent
reference would be passed into the constructor and then set by the child.
The parent list does not have any knowledge of the new child item at this
point. The child object is not added to the parent list unless there is a
successful dialog result and the new child object passed back in the finished
event args payload.
I think that’s best – that is the way CSLA is
designed to work, because that is the way data binding expects it to work.
You may be able to simplify your life slightly if you pretend to
BE data binding J
In other words, BusinessListBase (indirectly) implements ICancelAddNew,
which should allow you to tell the collection to remove the newly added child.
Failing that, the IEditableObject interface implemented by
BusinessBase also solves the issue. If you call CancelEdit() on a newly added
object, that object will automatically remove itself from its parent
collection. To do this, you do need to call BeginEdit() right after you’ve
added it to the collection.
Basically all you are doing in either case, is simulating what
data binding does, and in either case CSLA is designed to do the right thing.
Rocky
From: Jimbo
[mailto:cslanet@lhotka.net]
Sent: Friday, March 02, 2007 3:02 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: IEditableBusinessObject xml doc error
Rocky,
No problem
I guess that we do it your way
1. Add the new pending child to the collection. and all is well regarding the
parent ref setting etc.
2. Pass the pending child to the entry dialog - so we can also access the
parent list.
3. If the entry is not applied (dialog result = none say ) then in the return,
the pending child is simply removed from the list..
Copyright (c) Marimer LLC