My new object graph contains (one Root, of course) and many, many child objects, a few with grandchild objects. It is more efficient for me to create All objects in the graph at once, and let the user use the ones she needs. When Save is clicked, I want to save only those child objects that have user entered data. The unused child objects should not be saved.
Right now IsNew = IsDirty = IsSavable (Unless !IsValid in which case Exception must occur). Now I do need to have data validation, including mandatory fields, if the user does start editing the child object. But if the user completely igores a certain child object, what would be the best way to exclude it (and its children, if any) from the Save operation?
One solution that comes to mind is to have an IsUnused flag set to True until the user starts editing an object. Then I could delete the unused objects before the Save operation begins.
You can change the behavior of IsSelfDirty if you'd like - it is virtual. So is MarkNew iirc. It is a long-standing debate (back at least 10-12 years) about whether a new object is dirty automatically. CSLA defaults one way, but you can certainly switch the model.
Or, as you suggest, you can add another property in your custom base class, and probably set it to true in a MarkDirty or OnPropertyChanged override.
I see that MarkClean() is available. Any object in my graph that happens to be a parent must be saved if any of its descendants isDirty, even if the parent itself has not been touched by the user, So perhaps in all my Child_Creat() methods I can call MarkClean(). From that point on, the standard Csla behavior should probably take care of the rest.
Copyright (c) Marimer LLC