IEditableBusinessObject xml doc error

IEditableBusinessObject xml doc error

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


Jimbo posted on Friday, March 02, 2007

I notice that the <summary> descriptions for DeleteChild and SetParent are reversed.

On the subject of the various comments on the use of SetParent in Businessbase and BusinessListBase.:

Can a subclass of BusinessBase  call  SetParent independently of the ListBase call?
I have a case where I need to create a new child object for a dialog data entry, and depending on the dialog response either return the new object or nothing to the parent form which will then add the object to the parent list if its not nothing.  The intended "Parent" list object is needed  so that we can check for duplicate codes etc.

RockfordLhotka replied on Friday, March 02, 2007

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:

  1. When the child object is first referenced by the parent
  2. When the parent is deserialized (override OnDeserialized)

 

Jimbo replied on Friday, March 02, 2007

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.



RockfordLhotka replied on Friday, March 02, 2007

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.





Jimbo replied on Friday, March 02, 2007

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..




RockfordLhotka replied on Friday, March 02, 2007

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..






Jimbo replied on Saturday, March 03, 2007

It also keeps things consistent - since the same dialog will also be used to edit existing children.



Jimbo replied on Tuesday, March 06, 2007

Rocky,
There is a drawback with your recommendations. The pending child objects are not actually removed but are only marked for deletion.
In that case, we still end up with the problem that calling CancelEdit on the parent collection will restore the very pending child object that we rejected.
Defering Add or AddNew unless the dialog result is ok avoids this issue.
Andre's post 12707 talks about a similar situation..

.



ajj3085 replied on Tuesday, March 06, 2007

Jimbo,

Besides being marked for deletion, they should also be moved to an internal DeletedList, which should take them off any UI displaying the collection.

Copyright (c) Marimer LLC