Cannot "remove" Root objects from a collection?

Cannot "remove" Root objects from a collection?

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


CaymanIslandsCarpediem posted on Tuesday, December 26, 2006

I have an editable root collection.  However, the underlieing framework doesn't seem to like me trying to use syntax like this.Remove(item) to remove items from the collection.  If I try anything like this it gives me this error message "Invalid for root objects - use Delete instead".

I'm able to "get around" this via code like this.Items.Remove(item).  So I guess I have two questions. 1) is it meant to be like this or am I just messing something up? 2) if it is supposed to work like this.... why?  Why should the underlying framework decide I never want to remove a root item from a collection?

For a little background.  I'm hitting this issue in my code doing something very simliar to ActiveObjects.   Basically, when this item is deleted an event is raised in any collections subscribing to type of event on that type of objects.  If the current collection has a reference to that item which was just deleted, I want to remove that reference.

Anyone have any thoughts on this?

 

CaymanIslandsCarpediem replied on Tuesday, December 26, 2006

This same issue also stops you from using SetItem on a collection of root items since that code also includes a call to CopyToDeletedList which fails for root objects.

CaymanIslandsCarpediem replied on Tuesday, December 26, 2006

BTW, I can certainly accomplish what I'm attempting via code acting directly on the collections Items property but doing so seems to bypass list and property changed events so databound objects won't be refreshed on screen.

CaymanIslandsCarpediem replied on Tuesday, December 26, 2006

Nevermind, I'm just a bit slow after a too long holiday partying season Embarrassed [:$].  I was trying to use BusinessListBase, but should have been using EditableRootListBase.  It seems EditableRootListBase lets me use the Remove calls like I was thinking Big Smile [:D]

Copyright (c) Marimer LLC