BusinessBaseList and Remove(item)

BusinessBaseList and Remove(item)

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


dirtbert posted on Thursday, April 03, 2008

I have a collection implemented with BusinessBaseList, when I call the Remove(item) on the collection I can see the item move from the collection to the deleted items list.

What do I need to do in my collection implementation to get the Child_DeleteSelf to be called when I save the collection?

Or more generally, how does the deleted items list get cleared when the list is saved?

 

 

triplea replied on Friday, April 04, 2008

Assuming you are using CSLA 3.x then (and I am quoting PTracker) this should be sufficient:

RaiseListChangedEvents = false;

// update (thus deleting) any deleted child objects
foreach (ResourceAssignment item in DeletedList)
      item.DeleteSelf(resource);
// now that they are deleted, remove them from memory too
DeletedList.Clear();

If your list is a rot list (so not a child list of a root parent object) then just make sure you use the transactional attribute of manually start your transaction in your dataportal.

archimedes replied on Tuesday, August 12, 2008

The ResourceAssignment class in PTracker inherits from

BusinessBase<ResourceAssignment>, which as far as I can tell in 3.x (I'm using 3.5), there is no DeleteSelf method defined.  There is a private void Child_DeleteSelf on ResourceAssignment in the PTracker solution, but the question would be "how do you invoke that method via the data portal?".  DataPortal.Delete<T>(..) calls the DataPortal_DeleteABC, but no permutation of Child_DeleteABC.

rsbaker0 replied on Tuesday, August 12, 2008

archimedes:
There is a private void Child_DeleteSelf on ResourceAssignment in the PTracker solution, but the question would be "how do you invoke that method via the data portal?".  DataPortal.Delete<T>(..) calls the DataPortal_DeleteABC, but no permutation of Child_DeleteABC.

I'd think you would already be on the "server" side of the data portal when saving changes to a BusinessListBase (BLB) and could invoke child deletion methods directly rather than making further calls over the portal. (e.g. you're already in DataPortal_Update of the BLB when updating/removing the child objects)

RockfordLhotka replied on Tuesday, August 12, 2008

Right. One of the enhancements in 3.5, to reduce code, is that BLB contains code to automatically call the right methods on all the items in the collection.

If the BLB is your root object, you do need to override DataPortal_Update(), but in that method you'd just call base.Child_Update() and let BLB do the work.

If the BLB is a child of some other object, it is entirely automatic and you shouldn't have to worry about it at all.

Copyright (c) Marimer LLC