deleting objects
Deleting objects is a relatively simply process of flaging an object for deletion then saving the change to the database. Consider the need to delete myDefinition from the database. You simply say:
myDefinition.Delete();
myDefinition.Save();
However, our current version of the SQLite implementation does not support foreign key constraints. Consider this association, for more on associations, see this section (link).
myDefinition.Delete();
myDefinition.Save();
However, our current version of the SQLite implementation does not support foreign key constraints. Consider this association, for more on associations, see this section (link).
In this association the relationship between RoomDefinition and DoorTrigger implies that a DoorTrigger cannot be persisted in the database without a RoomDefinition defined.
This referential integrity is not supported. You could delete RoomDefinition and have several Door Triggers left behind that are orphans. You need to handle this yourself.
It's easy, however. We can scan through all the Triggers associated with myDefinition, mark all the times for deletion, then use the Repository.Commit() method to do a Unit of Work save.
foreach ( var TRIGGER in myDefinition.Triggers ) {
TRIGGER.Delete();
}
myDefinition.Delete();
Repository.Commit();
Recommendation
I recommend moving this code into behaviour in a method you define (link). That way if DoorTrigger had associations, the logic deleting the RoomDefinition wouldn't have to know that. It could say something like:
myDefinition.PurgeAndCommit();
This referential integrity is not supported. You could delete RoomDefinition and have several Door Triggers left behind that are orphans. You need to handle this yourself.
It's easy, however. We can scan through all the Triggers associated with myDefinition, mark all the times for deletion, then use the Repository.Commit() method to do a Unit of Work save.
foreach ( var TRIGGER in myDefinition.Triggers ) {
TRIGGER.Delete();
}
myDefinition.Delete();
Repository.Commit();
Recommendation
I recommend moving this code into behaviour in a method you define (link). That way if DoorTrigger had associations, the logic deleting the RoomDefinition wouldn't have to know that. It could say something like:
myDefinition.PurgeAndCommit();