Bug or optimization for DeleteChild()?

Bug or optimization for DeleteChild()?

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


marklindell posted on Tuesday, January 02, 2007

I have a scenario with CSLA v1 and v2 that requires some reflection by the community.

I have a business collection class where I am not using BeginEdit so my edit level is always 0.  I am adding and removing many new objects from the collection during my use case.  So many objects that when I serialize my state to disk it very quickly grows larger than 2MB.   This is greatly impacting the performance of the application unnecessarily.

What would be the purpose of adding new edit level zero objects to the deleted list in the DeleteChild method?

Does this seem like a solid optimization to add the following if statement to the DeleteChild method in BusinessCollectionBase?

private void DeleteChild(C child)
{
    // mark the object as deleted
   
child.DeleteChild();
    if (_editLevel > 0 && !child.IsNew)
        DeletedList.Add(child);
}

What would be the risk?  Am I missing any scenarios?  I reviewed CSLA 1.0 Pages 236-246 but everything centers around BeginEdit scenarios.

I tend to shy away from changes to CSLA but this one might be necessary unless I am just missing something.

Any feedback would be greatly appreciated.

D. Mark Lindell 

ajj3085 replied on Tuesday, January 02, 2007

That seems like it would work, although it seems odd you'd have so many new, deleted objects in a collection.

marklindell replied on Wednesday, January 03, 2007

Thanks for the response.  My logic was wrong in my suggested "if" statement.

It should be:

if (_editLevel > 0 || !child.IsNew)

 

ajj3085 replied on Wednesday, January 03, 2007

That would still add the new child to the deleted list, which I thought you were trying to prevent.

Brian Criswell replied on Wednesday, January 03, 2007

Not if the edit level is zero and the item is new.  The rest of the time it would need to be added to the deleted list.  Edit level greater than zero would need to place the item back in the main list and items that are not new would need to be deleted.

Copyright (c) Marimer LLC