Clear Items from BusinessListBaseClear Items from BusinessListBase
Old forum URL: forums.lhotka.net/forums/t/5331.aspx
bcrowell posted on Sunday, August 31, 2008
I'm trying to implement a method that clears all of the items from a BusinessListbase biz object and delete the underlying entries in the database. My method looks like this:
Public Overloads Sub ClearAll()
For Each res As ContentJournalAssignment In Me
Remove(res)
Next
End Sub
I'm calling the method like this:
Dim _CI As HTMLContentItem
_CI.GetContentItem(165500)
_CI.JournalList.ClearAll()
I'm getting this error:
Collection was modified; enumeration operation may not execute.
-----------------------
Can someone shed some light on this. I appear to not understand how to delete with deleting child objects. Thanks.
tetranz replied on Sunday, August 31, 2008
I think the collection's Clear method does exactly what you want with no more code required.
In general, if you want to Remove or Add (I'm not sure about change) items in a collection, you can't do that while looping through that same collection with a For Each. The iterator gets confused. The way I do that is to add the items to be removed to another temporary collection. A simple List of T will do. Then loop around that collection to do the Removing.
rasupit replied on Sunday, August 31, 2008
Other way is to use "for" loop and iterate from last to first item.
bcrowell replied on Sunday, August 31, 2008
Thanks for this. I've got the list.clear to work without errors but the underlying objects are not deleted. In fact, the delete_child method is never called even after an applyedit and save.
The same thing happens if I use the other sugestion and iterate backwards through the collection. The objects end up in the deleted list but don't actually get deleted from the dbase.
Any ideas? Many thanks.
bcrowell replied on Sunday, August 31, 2008
Thanks for this. I've got the list.clear to work without errors but the
underlying objects are not deleted. In fact, the delete_child method is
never called even after an applyedit and save.
The same thing
happens if I use the other sugestion and iterate backwards through the
collection. The objects end up in the deleted list but don't actually
get deleted from the dbase.
Any ideas? Many thanks.RockfordLhotka replied on Sunday, August 31, 2008
You are using 3.5 and the child data portal? That's the only way you'd automatically get Child_DeleteSelf() to be called. Note that the method name is Child_DeleteSelf(), not Child_Delete() for consistency with the DataPortal_XYZ method names.Copyright (c) Marimer LLC