You are here: Basics Operations & Concepts > Delete Behavior > Collections And Arrays

Collections And Arrays

Collections and arrays don't have a special behavior in db4o. When you delete a collection, the collection-members are not deleted. The collection and objects are two independent objects for db4o.

Removing From A Collection

To remove object from a collection you can simple use the regular collection-operations and then store that collection.

PilotGroup group = FindGroup(container);
Pilot pilot = group.Pilots[0];
group.Pilots.Remove(pilot);
container.Store(group.Pilots);

AssertEquals(3, AllPilots(container).Count);
AssertEquals(2, group.Pilots.Count);
DeletionExamples.cs: Removing from a collection doesn't delete the collection-members
Dim group As PilotGroup = FindGroup(container)
Dim pilot As Pilot = group.Pilots(0)
group.Pilots.Remove(pilot)
container.Store(group.Pilots)

AssertEquals(3, AllPilots(container).Count)
AssertEquals(2, group.Pilots.Count)
DeletionExamples.vb: Removing from a collection doesn't delete the collection-members

Remove And Delete Collection Members

If you want to delete a collection-member, remove it and then delete it.

PilotGroup group = FindGroup(container);
Pilot pilot = group.Pilots[0];
group.Pilots.Remove(pilot);
container.Store(group.Pilots);
container.Delete(pilot);

AssertEquals(2, AllPilots(container).Count);
AssertEquals(2, group.Pilots.Count);
DeletionExamples.cs: Remove and delete
Dim group As PilotGroup = FindGroup(container)
Dim pilot As Pilot = group.Pilots(0)
group.Pilots.Remove(pilot)
container.Store(group.Pilots)
container.Delete(pilot)

AssertEquals(2, AllPilots(container).Count)
AssertEquals(2, group.Pilots.Count)
DeletionExamples.vb: Remove and delete