Querying the saved Data
Querying the data we just saved is done with this code:
PersistenceManager pm = new PersistenceManager();
NDOQuery<Employee> q = new NDOQuery<Employee>(pm);
Employee e = q.ExecuteSingle();
Console.WriteLine(e.FirstName + " " + e.LastName);
Console.WriteLine(e.Address.City + ", " + e.Address.Zip);
The query only has to account for the employee object; the address is retrieved automatically. But this does not happen immediately when the employee is loaded. NDO normally creates so-called hollow objects that contain no data but instead have only an ObjectId. The first time one of the private persistent fields of a hollow object is accessed, the actual address data are loaded. In the example this happens as soon as the field street gets touched in the property Street. Note that you can override this behavior using prefetches.
Deleting the Data
Now you can add this line at the end of the code above:
It deletes not only the data row for the employee but also for the address. The parameter RelationInfo.Composite that was specified for the attribute NDORelation is responsible for that.
This solution is part of the tutorial samples. You can find the tutorial source code in the Tutorial folder beneath your NDO installation folder. The code up to here is placed in the Directory NDOTravelExpenses-Step 2.
The next section covers relations with cardinality n.