Referencing an Address in the Employee Table

Now the Employee class needs a reference to the Address class and a property for public access. The following code creates the relation to the address objects.


Address address;

As you can see, it is not enough to create a member variable of the correct type. It must also be declared that this is a relation. This is done with the attribute NDORelation. The attribute parameter specifies that the lifetime of the address object is coupled to the lifetime of the employee object. It is deleted from the database if the employee object is deleted or if the address variable is nulled.

The property for accessing the address looks like this:

public Address Address


    get { return address; }

    set { address = value; }


After rebuilding the assembly, the database structure has to be adjusted. The SQL script in the bin directory and the BuildDatabase() function take care of that. Note that you can use the diff-script residing in the bin directory too. Either execute it by hand or place the path to the diff script as parameter to the BuildDatabase function.

Note: If you press the Add Relation button, NDO shows a dialog helping you to produce the code necessary for a relation. If you exit the dialog with OK, the code will be inserted at the current cursor position.
Add Relation