By default db4o only deletes objects which are passed to the delete-method and doesn't delete referenced objects. You can easily change that. Configure the cascading deletion behavior in the configuration for certain classes or certain fields.
For example we mark that the object in the 'pilot'-field is also deleted:
IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration(); config.Common.ObjectClass(typeof (Car)).ObjectField("pilot").CascadeOnDelete(true); using (IObjectContainer container = Db4oEmbedded.OpenFile(config, DatabaseFile)) {
Dim config As IEmbeddedConfiguration = Db4oEmbedded.NewConfiguration() config.Common.ObjectClass(GetType(Car)).ObjectField("pilot").CascadeOnDelete(True) Using container As IObjectContainer = Db4oEmbedded.OpenFile(config, DatabaseFile)
When we now delete the car, the pilot of that car is also deleted.
Car car = FindCar(container); container.Delete(car); // Now the pilot is also gone AssertEquals(0, AllPilots(container).Count);
Dim car As Car = FindCar(container) container.Delete(car) ' Now the pilot is also gone AssertEquals(0, AllPilots(container).Count)