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

object association parent management

Suppose you have the following association:​
Picture
SQLINQ will generate support for the master-child association by creating:
  • SolarSystem   Ship.TheSolarSystem
  • IList<Ship>   SolarSystem.Ships

In order to manage the two lists, you simply say:
  • myShip.TheSolarSystem = mySolarSystem;

And the system will automatically remove "mySolarSystem" from the current list it is assigned to, and reassign it to the IList on mySolarSystem, assuming both objects are not null.  This is the code it generates:
public SolarSystem TheSolarSystem { 
    get { return _TheSolarSystem.Value; } 
    set { 
        if ( _TheSolarSystem.Value != value ) {

            // Remove the reference of this instance in the original parent's list
            if ( _TheSolarSystem.Value != null ) 
                _TheSolarSystem.Value.Ships.Remove( this )  // Ignored if not present or loaded

            _TheSolarSystem.Value = value; 

            // Add this to the new parent's list
            if ( _TheSolarSystem.Value != null )
                _TheSolarSystem.Value.Ships.Add( this );

            IsDirty = true;
        }
    } 
}