Rookie question about deleteSelf of items in lists

Rookie question about deleteSelf of items in lists

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


gartnerj posted on Monday, November 12, 2007

OK, I've seen the examples where a list does a foreach loop for the deletion of items so marked.

The item.DeleteSelft is called, which deletes the database entry for the item, then it is marked MarkNew.

I DON'T see where the item is actually removed from the LIST BO class itself. It looks like the deleted item, although marked NEW (so subsequent saves should't re-add them to the db) are not actually removed from the list, unless you go back out an re-fetch the list from the db.

Any help here in understanding what is going on greately appreciated.

juddaman replied on Monday, November 12, 2007

Hi

If your talking about this kind of thing (taken for ProjectResources.cs).

 foreach (ProjectResource obj in DeletedList)
        obj.DeleteSelf(project);
      // now that they are deleted, remove them from memory too
      DeletedList.Clear();

After calling DeleteSelf on each child, Clear() is called on the list, therefore deling each child from memory.

Not to sure where you saw MarkNew() being called. If you point me at it I'll take a look.

HTH
George

juddaman replied on Monday, November 12, 2007

Actually, I guess you saw the MarkNew() in the DeleteSelf() method in the child class. The child is deleted from memory in the parent collection class, when Clear() is called.

George

gartnerj replied on Tuesday, November 13, 2007

Yes, that is where I saw the MarkNew.

I thought the DeletedList.Clear() ONLY removed the items from the DeletedList deleted objects tracking, not the actual BO list.

My front end user is saying that when they "delete" objects out of the list (which is part of another BO), the item is removed from the db, but when the other BO is saved again, the "old" deleted items in the list are being readded to the database.

BTW, I appreciate the help here!

juddaman replied on Tuesday, November 13, 2007

Hi

Sorry you've lost me. If you attach the code for the root object, the collection and collection child objects I'll take a look.

George

ajj3085 replied on Tuesday, November 13, 2007

That should be handled via databinding; your grid control asks the binding source to remove a specific object.  Csla's BusinessListBase overrides RemoveItem (IIRC) so that instead of just removing it from the "real" list, it puts it into DeletedList so that you can do the database delete when Save is called.   It also calls the Delete method on the BO "deleted."

If that's not happening, something fishy is going on.  Are you sure the object is removing itself from the database?  I would check there first.

gartnerj replied on Monday, November 19, 2007

Thanks for the further explanation.
It turns out, the UI coder who complained about this had removed the DeletedList.Clear from his copy of the business object code, so while it DID remove items from the db (since the item.delete was called), the actual deleted items were never removed from the list itself.

Copyright (c) Marimer LLC