You are here: Configuration > Adding a Field Index

Field Specific Configuration

Some settings are field-specific. It's part of the object-configuration, which is available on the client, server and embedded-mode of db4o.

Its recommended that you use the same configuration for the client and the server.

Access the Field Configuration

The configuration for a field follows the same pattern. First you specify for which type this configuration applies. You pass the type or the name as string. Then you navigate to the specific field by passing the field name as string.

Note that you need to specify the field-name and not the property-name, also for auto-properties.

Adding a Field Index

Index dramatically speed up queries. You should index all fields which you run queries on. See "Indexing"

IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration();
configuration.Common.ObjectClass(typeof (Person)).ObjectField("name").Indexed(true);
ObjectFieldConfigurations.cs: Index a certain field
Dim configuration As IEmbeddedConfiguration = Db4oEmbedded.NewConfiguration()
configuration.Common.ObjectClass(GetType(Person)).ObjectField("name").Indexed(True)
ObjectFieldConfigurations.vb: Index a certain field

As an alternative you also can use the appropriate Attribute on the field which you want to index.

[Indexed]
private string zipCode;
ObjectFieldConfigurations.cs: Index a field
<Indexed()> _
Private m_zipCode As String
ObjectFieldConfigurations.vb: Index a field

Cascade On Activate

db4o uses the concept of activation to avoid loading to much data into memory. When this setting is turned on, the object referenced by this field is activated, when the object is activated.

IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration();
configuration.Common.ObjectClass(typeof (Person)).ObjectField("father").CascadeOnActivate(true);
ObjectFieldConfigurations.cs: When activated, activate also the object referenced by this field
Dim configuration As IEmbeddedConfiguration = Db4oEmbedded.NewConfiguration()
configuration.Common.ObjectClass(GetType(Person)).ObjectField("father").CascadeOnActivate(True)
ObjectFieldConfigurations.vb: When activated, activate also the object referenced by this field

Cascade On Update

When the object is updated, the object referenced by this field is also updated.

IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration();
configuration.Common.ObjectClass(typeof (Person)).ObjectField("father").CascadeOnUpdate(true);
ObjectFieldConfigurations.cs: When updated, update also the object referenced by this field
Dim configuration As IEmbeddedConfiguration = Db4oEmbedded.NewConfiguration()
configuration.Common.ObjectClass(GetType(Person)).ObjectField("father").CascadeOnUpdate(True)
ObjectFieldConfigurations.vb: When updated, update also the object referenced by this field

Cascade On Delete

When the object is deleted, the object referenced by this field is also deleted

IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration();
configuration.Common.ObjectClass(typeof (Person)).ObjectField("father").CascadeOnDelete(true);
ObjectFieldConfigurations.cs: When deleted, delete also the object referenced by this field
Dim configuration As IEmbeddedConfiguration = Db4oEmbedded.NewConfiguration()
configuration.Common.ObjectClass(GetType(Person)).ObjectField("father").CascadeOnDelete(True)
ObjectFieldConfigurations.vb: When deleted, delete also the object referenced by this field

Rename Field

Allows you to rename this field. . See "Refactoring and Schema Evolution"

IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration();
configuration.Common.ObjectClass(typeof (Person)).ObjectField("name").Rename("sirname");
ObjectFieldConfigurations.cs: Rename this field
Dim configuration As IEmbeddedConfiguration = Db4oEmbedded.NewConfiguration()
configuration.Common.ObjectClass(GetType(Person)).ObjectField("name").Rename("sirname")
ObjectFieldConfigurations.vb: Rename this field