This is a migrated thread and some comments may be shown as answers.

Remove from collection

1 Answer 103 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Robert Lautenbach
Top achievements
Rank 1
Robert Lautenbach asked on 24 Jun 2010, 03:39 PM
I'm using a reverse mapping on a project. I have a class that exposes a collection of another class type. When I use .remove(objectInstance) on the collection property I am able to remove from the working collection, but the change does not persist to the database.

To go a little deeper, I have two rad list boxes. I'm adding new selections and deleting unselected elements on save.

My underlying code uses the parent collection property to add new elements:
parentObject.Children.Add(childObjectToAdd) 

And .Remove() to remove unselected elements:
parentObject.Children.Remove(childObjectToRemove) 

After looping through I call:
scopeInstance.Add(parentObject)
scopeInstance.Transaction.Commit()

The newly added object linkages save. But the removed linkages do not delete. The only way I can get it to work is to delete the child object via the scope:
parentObject.Children.Remove(childObjectToRemove)
scopeInstance.Remove(childObjectToRemove)

Since I'm checking my children collection for object existence repeatedly, if I only delete via scopeInstance.Remove(..) and not parentObject.Children.Remove(..) I get an error about attempting to read/write elements marked for deletion.

Is there another way to go about persisting .Remove() calls for a child collection property?

1 Answer, 1 is accepted

Sort by
0
Petko_I
Telerik team
answered on 30 Jun 2010, 03:38 PM
Hello Robert Lautenbach,

Sorry for the delayed answer. On principle to be able to delete the items both from the RadListBox and the database, the OpenAccessDataSource should be configured to allow deletes. Furthermore, you need to set the DataKeyField of the RadListBox to the identifier of the record you want to delete. Finally, you also need to set AllowAutomaticUpdates and AutoPostBackOnDelete in the RadListBox to true.

However, you seem to have encountered a problem with our RadListBox and it will be fixed. Once again, we are sorry for the inconvenience this might have caused you. Your Telerik points have been updated.


Regards,
Petko_I
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Development (API, general questions)
Asked by
Robert Lautenbach
Top achievements
Rank 1
Answers by
Petko_I
Telerik team
Share this question
or