Ninja Database Pro
Inserting and Updating Records
Basic Tasks > Inserting and Updating Records

When objects are saved the first time, the primary key is set.  Subsequent saves of the object are considered updates.  Parent and child objects are automatically saved.  Foreign keys are automatically maintained between parents and children.  It is possible to save parents and children as separate tables.  See Setting Up Relationships.    

 

C# Example:

 

Db db = new Db("MyDatabaseDirectory", "MyDatabaseName");

 

//Licensed Mode

//db.UserName = "John Smith 101224";

//db.LicenseKey = "aousdf832jasf==";

 

//Set before OpenDatabase. Default storage is IsolatedStorageDatabase. Other options are:

//db.Storage = new MemoryDatabase(); //In memory database

//db.Storage = new FileDatabase(); //Valid only for non Silverlight projects

 

db.OpenDatabase();

 

Person person = new Person();

person.DateCreated = DateTime.Now;

person.Name = "John";

 

//This is an insert

db.Save(person);

 

//This is an update

person.Name = "John Smith";

db.Save(person);

 

Person personCopy = db.Load<Person>(person.PersonId);

 

db.CloseDatabase();