You are here: Advanced Features > Refactoring And Schema Evolution > Renaming API

Renaming API

db4o provides a special API to move classes between namespace, rename classes or fields.

Rename a Class

Use the configuration API to rename a class.You need to rename the class before you open the database.

Remember to include the assembly name.

configuration.Common.ObjectClass("Db4oDoc.Code.Strategies.Refactoring.PersonOld, Db4oDoc")
    .Rename("Db4oDoc.Code.Strategies.Refactoring.PersonNew, Db4oDoc");
RefactoringExamples.cs: Rename a class
configuration.Common.ObjectClass("Db4oDoc.Code.Strategies.Refactoring.PersonOld, Db4oDoc") _
    .Rename("Db4oDoc.Code.Strategies.Refactoring.PersonNew, Db4oDoc")
RefactoringExamples.vb: Rename a class

Rename a Field

Use the configuration API to rename a field. You need to rename the field before you open the database.

Remember to include the assembly name.

configuration.Common.ObjectClass("Db4oDoc.Code.Strategies.Refactoring.PersonOld, Db4oDoc")
    .ObjectField("name").Rename("sirname");
RefactoringExamples.cs: Rename field
configuration.Common.ObjectClass("Db4oDoc.Code.Strategies.Refactoring.PersonOld, Db4oDoc") _
    .ObjectField("name").Rename("sirname")
RefactoringExamples.vb: Rename field

Rename Step by Step

The safe order of actions for renaming is:

  1. Backup your database.
  2. Close all open object containers if any.
  3. Rename classes or fields in your application.
  4. Add the renaming call to on the configuration before opening the database.
  5. Pass the configuration with the rename-information to the object container factory. Open the database and you're ready to work with the renamed classes or fields.