Call EndEdit on Clone instead of unbinding before save

Call EndEdit on Clone instead of unbinding before save

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


JoshL posted on Monday, January 26, 2009

In CSLA, the recommendation is to unbind business objects from BindingSources, prior to saving them. The recommended sequence of events, as I understand it, is:
1. Call EndEdit on all BindingSources that are bound to the subject business object

2. Unbind all BindingSources that are bound to the subject business object, by setting DataSource to null or to the business object type

3. Save

4. Rebind the BindingSources to the object returned from the Save method

CSLA creates a clone of the business object prior to saving it. Is there any reason not to call EndEdit on the clone and skip the "UnBind" step above? Then one could simply rebind the new object and allow the binding hierarchy to propogate normally based on the child objects. This would save a lot of work, especially in cases where there is a hierarchy of controls each responsible for the UI for a given child object.

RockfordLhotka replied on Tuesday, January 27, 2009

The trick is that collections are bound such that only one item is current, not the whole collection. So what you propose might be possible, but you'd have to scan the entire object graph to locate any and all "current" objects so you could commit their changes.

Copyright (c) Marimer LLC