Hi,
I have a collection that derives from BusinessListBase. How do I remove an item from the collection so that I can add it to another colection? When I try, it wants to mark the item as deleted and add it to the deleted list. I don't want to do this, I just want to move it to a different list.
Thanks.
Csla doesn't support that concept. At item can have one and only one parent in its lifetime. You could create a new item with the same values (but probably not the same key values) and put that in the list, then do the delete.
See this thread for more details regarding the "one parent" statement.
Wondering out loud here, because I did something vaguely similar in my app....
Could you not do something along these lines?
//Get the Object...
MyObject obj = MyList.GetObjectByID(id);
//Make a non list copy
MyObject obj2 = obj.Clone();
//Add the object to the new list
myList2.Add(obj2);
obj.Delete();
//Flush the Delete
myList = myList.Save();
//Write the new DB records
myList2 = myList2.Save();
Like I said, since I did something similar, and it works for me... I'd like to know the downfall of this. (Besides the 2 database hits)
You can probably do this, as long as you know what you are doing
Assuming you are using CSLA .NET 3.8 this should work, because when you add the child to the new list, the new list should change the Parent property and edit level to match that of the new list.
The only thing I don't know for sure is whether the source list will properly unbind the child's PropertyChanged and ChildChanged events. I think that happens when the child is moved to DeletedList, but it might not happen - because it wouldn't be really necessary - so you'd have to check that.
The safer solution is to do a Clone() as you suggest, because the clone won't have any legacy event hookups to worry about, nor will its IsDeleted flag be set.
You still need to make sure to completely remove the old child from the original list - both the list and DeletedList, or you could find your being deleted out from under you unexpectedly when the original list is saved.
Thanks, that seems to work OK. I'm not actually using the PropertyChanged/ChildChanged events on this object so thats not an issue.
Thanks, that seems to work OK. I'm not actually using the PropertyChanged/ChildChanged events on this object so thats not an issue.
It doesn't matter if you use them or not - those events get hooked by the collection, and if they don't get unhooked you could end up with some really strange results and/or memory leaks.
Copyright (c) Marimer LLC