tags:

views:

49

answers:

1

How can I do this?
I stored an object in db4o, e.g:

class Person {
    string _name;
    int _age;
}

now, after hundrets of Persons stored in the db, I've added a new field:

class Person {
    string _name;
    int _age;
    bool? _newField;
}

When I load the old classes with the new class, the _newField will be null or the default value. When I save it back to the db, the added field is obmitted.

How can I update all existing objects with the new field? Is that possible?

+1  A: 

As you said, when you add a new field it has the default value for existing object. Now you just can load a object, set a value to the field and store it again. Then the data is stored for that field. See also on the documentation.

So you should be able to load a object and update it:

IObjectContainer container = ...
var persons = from Person p in container                  
              select p;

foreach(var p in persons){
     p.NewField = true; // new value
     container.Store(p);
}

// done

I think the default value for a Nullable bool should be 'empty'.

If that doesn't work, it looks like a bug. Which version are you using?

Gamlor
Ok, the field seems to be updated. But the "VisualStudio Objectmanager Plugin" doesn't show it. I'm using 7.12.132.14217
chriszero
Oh, then it could be a ObjectManager bug.
Gamlor