You are here: Advanced Features > Refactoring And Schema Evolution > Field Refactoring Limitation

Field Refactoring Limitation

For most cases changing the field type isn't an issue. db4o keeps the old values around and you can access the old values without issues. See "Field Type Change"

However there's one limitation to this mechanism. You cannot change the type of a field to its array-type and vice versa. This only applies if it's the same array-type. For example:

Refactoring To An Array-Field Step by Step

When you change the type of a field to its array-type equivalent, you can do this only by copying the old data to a new class. In this example we have a Person-class which has its name in a string field. Now we want to change that to a string array to support multiple names.

  1. Create a copy of the Person-class with a new name.
  2. Do the refactoring on the new Person class
  3. Query for old instances of the old Person-class and copy the values over to the new class.
IList<PersonOld> oldPersons = container.Query<PersonOld>();
foreach (PersonOld old in oldPersons)
{
    PersonNew newPerson = new PersonNew();
    newPerson.Name = new string[] {old.Name};
    container.Store(newPerson);
    container.Delete(old);
}
ChangeArrayType.cs: Copy the string-field to the new string-array field
Dim oldPersons As IList(Of PersonOld) = container.Query(Of PersonOld)()
For Each old As PersonOld In oldPersons
    Dim newPerson As New PersonNew()
    newPerson.Name = New String() {old.Name}
    container.Store(newPerson)
    container.Delete(old)
Next
ChangeArrayType.vb: Copy the string-field to the new string-array field

Note that this example doesn't change existing references from the old instances to the new ones. You need to do this manually as well.