Db4o, how to update an object if a field has been added?

How can i do this? I saved the object in db4o, for example:

class Person {
    string _name;
    int _age;
}

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

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

When I load old classes into a new class, _newField will be null or the default value. When I put it back in db, the added field will be deleted.

How to update all existing objects using a new field? Is it possible?

+3
source share
1 answer

, . , . . . documentation.

, :

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

, Nullable bool "".

, . ?

+2

Source: https://habr.com/ru/post/1766784/


All Articles