ELENESSKI GAMES
  • Home
  • Games
    • Worzzler
    • The Lost Tribes
  • Unity
    • Facade Generator for Archimatix
    • Elenesski Object Database
    • Generic Move Camera
    • Unity C# Library
  • SQLINQ
    • Change Log
    • Concepts >
      • Overview
      • The Patterns
      • Database & Factories
      • Working with Tables
      • Custom Queries
      • Lazy Loading
      • Units of Work
    • Video Tutorials
    • Getting Started
    • Code Examples >
      • Implementing Behavior
      • Finding Objects
      • Custom Searches
      • Converters and Transformers
      • Object Association Management
      • New Objects
      • Creating Database
      • Associating Objects
      • Deleting Objects
      • Validating Objects
      • Saving
    • Sample Model >
      • Tutorial Model
      • Table Classes Code
      • Domain Classes Code
      • Factories Code
    • OSX Developers
    • Bridge Building
    • External Websites
    • Class Documentation
  • Presentations
    • 3D Ship Design
  • Music
    • Jamendo (Main)
    • Blend
    • Sound Cloud
    • Mixcloud (DJ)
    • DJ Demos
  • YouTube

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).
Picture
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();