Frage

Let's say I have a model that looks like this (fake, but as an example)

public class PackageItem
{
    public string Name { get; set;}
    public bool Available { get; set;}
}

public class Package
{
    public string Recipient { get; set;}
    public List<PackageItem> Items { get; set;}
}

First a new instance of Package is created with just the Recipient set to some value.

Some time later, (the database has been closed in between), I retrieve it from the database and add items to it:

var packages = database.Query<Package>()
foreach(var package in packages)
{
    package.Recipient = "Bla bla bla";
    package.Items.Add(new PackageItem() { Name = "SomeName", Available = true });
    database.Store(package);
}
database.Commit();

At this point the changes to the Recipient property are saved in the database, but the additions to the Items property are not.

I found some information about db4o not knowing anything has changed because the reference to the List did not change and db4o does not know about changes to the List itself... is this correct?

And how should one deal with a List of T when using db4o?

*Update: * I thought executing

database.Store(package.Items);

would help but it does not.

This is all using db4o v8 on Debian with Mono 2.11

War es hilfreich?

Lösung

You've stumbled upon the activation depth.

Take a look at the documentation. You either need to explicilty store the changes in the collection:

 database.Store(page.Items)

Or increase the update depth. Or switch to transparent persistence.

Andere Tipps

besides the options mentioned by Gamlor you can also explicitly define update depth in Store method itself (overloaded Store method is hidden in Ext) like:

database.Ext().Store(package, int.MaxValue);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top