object association parent management
Suppose you have the following association:
SQLINQ will generate support for the master-child association by creating:
In order to manage the two lists, you simply say:
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:
- 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;
}
}
}
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;
}
}
}