Creating the Client
Right-click on the References entry of the TravelAccount test app project in the Solution Explorer.
Select Add Reference.
In the Add Reference dialog select the tab Projects and add a reference to BusinessClasses. Close the dialog by pressing OK.
Right-click on the TravelAccount Entry in the Solution Explorer and select Set as Startup Project.
Open the NDO configuration dialog for the TestApp project and select Sqlce as the SQL dialect of the database.
Press the New button next to the edit field for the Default Connection String. In the next dialog press the Browse button (...). You get a standard file dialog where you can enter an database filename. Choose a directory where you want the database to be created and type a Name like NDOTestDB.
Click Store and in the Database dialog click OK – you don't need a password. The connection string to the new database is inserted in the Default Connection String edit box. Now close the NDO Configuration Dialog by pressing OK.
Now open the Program.cs in the Solution Explorer that was created by Visual Studio and insert this Code:
static void Main(string args)
Employee e = new Employee();
e.FirstName = "Mirko";
e.LastName = "Matytschak";
PersistenceManager pm = new PersistenceManager();
The interesting part starts with the fourth line. The PersistenceManager is created here. It is the central class with which applications interact with the persistence layer.
The call to MakePersistent() registers the object at the persistence layer. Before this call, the code added by the NDO Enhancer does not come into effect. Among other things the enhanced code reports every access to private variables to NDO, so that NDO can load object data if necessary or mark an object as dirty after a write access.
pm.Save() stores created or changed objects to the database. Objects marked for deletion will also be deleted from the database. In the case of our example the call to Save() simply stores the new object.