EArgumentOutOfRangeException Removing Associated Entities

I have two Entities, where both are related 1:n.
So I have a ManyValuedAssociation on the one side, and a Association on the other side.

Both Associations got CascadeTypeAll.

Removing one of these 2 Entities, I'll get an EArgumentOutOfRangeException out of TObjectManager.CascadeRemove, while List.Delete(List.Count - 1); is called.

Looks like Entity is removed 2 Times and "Trash" is not checked anymore.

Please provide the call stack. Please provide more info. I don't know what is List. I don't know exactly what the code you are using.

All I can say is Aurelius doesn't manipulate lists in many-valued associations at all. And also, if you call Manager.Remove(Entity) and such entity is in a list, the list will keep a reference to a destroyed object and it's up to you to manage that. Unless you set Manager.DeferDestruction to true, then the object will not be destroyed when Remove is called.

is the method, that calls List.Delete(List.Count - 1);. that's were the error occurs, I have a little sample project, I'll send to you, so that you can step into this

For associations, you should not add the TCascadeType.Remove to the cascade configuration. Use this:

    [Association([], CascadeTypeAllButRemove)]
    FParent: TEntity;

Well in my case these are 1:1 relations.
And I'm not able to switch the ManyValuedAssociations with the Associations, because I need the SubProp-functionality in my entity holding the Association...

Maybe I could remove them in OnDeleting, but these are proxies, so maybe the are not fetched yet...
Correct me, if I'm wrong, but fetching them would corrupt the transaction.

Well, you have a cyclical removal here. You have the association removing the many-valued association, and the many-valued association removing the association.

Choose one side and delete the other side manually.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.