MarkOld, IsDirty, and Child Collections?

MarkOld, IsDirty, and Child Collections?

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


gartnerj posted on Wednesday, August 29, 2007

Folks,
I'm having a bit of trouble understanding how to have a BO with a collection of Child objects to be marked IsDirty=false on create when I have added items to the child collection.

I have done the override of:

public override bool IsDirty

{

get { return base.IsDirty || _contactsList.IsDirty; }

}

but when I do the MarkOld() before returning from the BO, it looks to the UI like the BO is marked Dirty (and since on create I have done an Add to the list, I'm guessing it would be.  )

How do I set the _contactList.IsDirty to false in this case (since IsDirty on the list is only a get parm)??

Thanks,

Jim

RockfordLhotka replied on Wednesday, August 29, 2007

The child object you add to the list must also be not dirty. Collections are dirty or not dirty based entirely on the state of their children (and the deletedList, which doesn't matter here).

So make that new child be not dirty and you should be set.

RockfordLhotka replied on Wednesday, August 29, 2007

One warning though - because if you do make that child not dirty, and the user never edits the child then it would never get saved (not changed after all). So you may have to come up with a scheme by which you always save child objects even if they aren't dirty or something.

gartnerj replied on Wednesday, August 29, 2007

Thanks Rocky -- the save actually builds XML from all of the objects in the BO to save to the db, so the "children" don't save themselves for this object -- only the parent.

I did check the children of list, and that object has a MarkOld() on create/fetch (i was pretty sure from the book that was what I needed to do), so I'm not sure why this is still flagging the parent as IsDirty -- I'll have to do some more investigation.

culprit replied on Thursday, August 30, 2007

I have a similar setup but I am having trouble making the Data_Update routine fire even though the childlist shows it to be dirty and I overrode the IsDirty flag as you did. Does anyone know what I might be doing wrong here?

alex.williamson@grampianfasteners.com replied on Wednesday, October 15, 2008

Did you solve this? I'm having the same problem, currently can't get my parent BO to update when I call save and it has a new child object.

I have a parent BO which has a list of children which is populated through the parent correctly. Do I call parent->list->AddNew() and work with the object? I'm sure I've got this to work before. I'm working in VB.

Or should it be created through the UI:

Dim temp_childitem as childitem = New ChildItem
Dim existing_parentitem.listofchildren.add(temp_childitem)
editform_open_withchild(childitem)

alex@alexw.co.uk replied on Wednesday, August 24, 2011

Answer to this of course was to override AddNewCore()

Copyright (c) Marimer LLC