Ninja Database Pro
Deleting Records
Basic Tasks > Deleting Records

You can delete records by primary key, do a bulk delete, or save a list of items where the class has a IsDeleted property.  See the IsDeleted property for more information.  Child records are automatically cascade deleted.  The count returned from the delete method includes the children that are also deleted. 

 

Example deleting by primary key

 

NinjaDbPro db = new NinjaDbPro("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.Name = "John Smith";

 

//Save it

db.Save(person);

 

//Delete it by primary key

int recordsDeleted = db.Delete<Person>(person.PersonId);

 

db.CloseDatabase();