Adding item to child collection not making parent Dirty

Adding item to child collection not making parent Dirty

Old forum URL:

JonM posted on Tuesday, February 15, 2011

I'm using CSLA 4.1 in a SL/MVVM+Dataportal config.  I've got an editable root with a child collection.  When I add a new item to the child collection it does not make the editable root dirty.  If I modify the new item in any way then the editable root gets marked dirty.  It is almost like the isdirty check is not happening when I add the item to the collection.  When the child is added to the collection it is marked as 'dirty' and 'isnew'.  Any ideas?  I'm just calling a  Root.ChildCollection.Add(ChildItem.NewChild(criteria)).   Should I be adding items in a different way?

RockfordLhotka replied on Tuesday, February 15, 2011

Since this is SL, is it possible you are hitting an async timing issue? What does your NewChild factory method do exactly? Call DataPortal.CreateChild, or DataPortal.Create?

The IsDirty implementation in BusinessBase is pretty simple - it gets the IsDirty value from its child (the collection). The implementation in the collection gets its value by looping through all the child objets in the collection. Nothing is cached or event-driven - it is calculated based on the actual values of the objects when the property is checked.

This means that async scenarios can be confusing, because if the new child has yet to be created and added when IsDirty is called, it could easily return false because the new child object isn't in the collection yet.

JonM replied on Tuesday, February 15, 2011

I think I figured it part way out.  I had a custom rule that was throwing an error.  I put some extra checks in and that seems to have fixed it.  Weird.  So it looks like the rules manager swallows exceptions and sort of considers the object invalid?

Copyright (c) Marimer LLC