I've just committed a change to CVS to automatically clean up one-to-many associations without some of the manual effort that currently occurs.
There are a few things that affect this behaviour as follows:
1. SaveAutomatic must be on for the association to be checked.
2. DeleteAutomatic controls wether the object from the collection is deleted from the database or if it just has the association entry attributes cleared.
For example, assume we have a one-to-many association between class A and B.
ObjA has a collection of ObjB's and we remove one ObjB from that collection. We then save ObjA...
Scenario 1 (SaveAutomatic="false" DeleteAutomatic="false")
-- Nothing happens. Programmer must clean up ObjB manually.
Scenario 2 (SaveAutomatic="true" DeleteAutomatic="false")
-- Since DeleteAuto is off we cannot delete the ObjB (it may be referenced elsewhere). Instead we will clean the attributes of ObjB that contain the back reference to ObjA. Initially we will attempt to populate with Nothing, however if that fails we will try to populate with the DBNull alias value.
Scenario 3 (SaveAutomatic="true" DeleteAutomatic="true")
-- ObjB will be deleted from the database. If the programmer manually deleted ObjB before calling the save on ObjA then the delete will fail. This failure is captured in the persistence broker and no exception will be thrown.
I've done some inital testing and it seems to work OK so if you have problems please let me know.
- Richard
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I've just committed a change to CVS to automatically clean up one-to-many associations without some of the manual effort that currently occurs.
There are a few things that affect this behaviour as follows:
1. SaveAutomatic must be on for the association to be checked.
2. DeleteAutomatic controls wether the object from the collection is deleted from the database or if it just has the association entry attributes cleared.
For example, assume we have a one-to-many association between class A and B.
ObjA has a collection of ObjB's and we remove one ObjB from that collection. We then save ObjA...
Scenario 1 (SaveAutomatic="false" DeleteAutomatic="false")
-- Nothing happens. Programmer must clean up ObjB manually.
Scenario 2 (SaveAutomatic="true" DeleteAutomatic="false")
-- Since DeleteAuto is off we cannot delete the ObjB (it may be referenced elsewhere). Instead we will clean the attributes of ObjB that contain the back reference to ObjA. Initially we will attempt to populate with Nothing, however if that fails we will try to populate with the DBNull alias value.
Scenario 3 (SaveAutomatic="true" DeleteAutomatic="true")
-- ObjB will be deleted from the database. If the programmer manually deleted ObjB before calling the save on ObjA then the delete will fail. This failure is captured in the persistence broker and no exception will be thrown.
I've done some inital testing and it seems to work OK so if you have problems please let me know.
- Richard