Creating the Client Application
Paste this code into your client project:
PersistenceManager pm = new PersistenceManager();
// Make sure to build the database
Employee e = new Employee();
e.FirstName = "John";
e.LastName = "Doe";
Travel t = e.NewTravel();
t.Purpose = "Inhouse Training";
t = e.NewTravel();
t.Purpose = "TechEd 2006";
Address a = new Address();
e.Address = a;
Two travels are created and assigned to the object, representing Mr. Doe. These travels are stored in the table travels.
At this point you might be interested in watching the database structure that results from the two relations of the Employee class to Address and Travel. NDO creates a schema file <Assemblyname>.ndo.xsd, which is very helpful to examine the database structure. For our sample it looks like this:
As expected, three tables have been generated. Every table has an id column of type int. This is the standard in NDO. Other types are also possible, have a look at the chapter Objects and Object Identity. The relations between the tables are also visible. The 1:1 relation is realized with a foreign key column IDAddress in the Employee table. This foreign key refers to the key ID in the Address table. The 1:n relation is implemented with a foreign key column IDEmployee in the table Travels. This key refers to the column ID in the Employee table. The tables and relations generated by NDO comply with the common design rules for relational databases. This allows mapping the classes to existing databases also following these rules.
While the picture above represents the DataSet description in the .xsd file, NDO generates the DDL code for exactly the same database structure.