/// <summary> /// How to delete an object using OID /// </summary> public void Step14() { ODB odb = null; try { // Open the database odb = ODBFactory.Open(ODB_NAME); Sport tennis = odb.GetObjects <Sport>(new CriteriaQuery(typeof(Sport), Where.Equal("name", "Tennis"))).GetFirst(); // Firts re-create Agassi player - it has been deleted in step 13 Player agassi = new Player("Andr\u00E9 Agassi", new DateTime(), tennis); odb.Store(agassi); odb.Commit(); IQuery query = new CriteriaQuery(typeof(Player), Where.Like("name", "%Agassi")); Objects <Player> players = odb.GetObjects <Player>(query); // Gets the first player (there is only one!) agassi = players.GetFirst(); OID agassiId = odb.GetObjectId(agassi); odb.DeleteObjectWithId(agassiId); odb.Close(); odb = ODBFactory.Open(ODB_NAME); // Now query the databas eto check the change players = odb.GetObjects <Player>(); Console.WriteLine("\nStep 14 : Deleting players"); int i = 1; // display each object while (players.HasNext()) { Console.WriteLine((i++) + "\t: " + players.Next()); } } finally { if (odb != null) { // Close the database odb.Close(); } } }