tags:

views:

70

answers:

1

So I'm probably doing something tragically wrong with db4o to cause this issue to happen...but every time I reset my context I lose all of my objects. What I mean by this is that as soon as my container object goes out of scope (due to an IIS reset or whatever) I can no longer retrieve any of the objects that I previously persisted. Within the scope of a "session" I can retrieve everything but as soon as that "session" dies then nothing is returned. What's odd is that the database file continues to grow in size so I know everything is in there it just never gets returned after the fact. Any idea what's going on?

Here is my generic wrapper for db4o:

public class DataStore : IDisposable {

    private static readonly object serverLock = new object();
    private static readonly object containerLock = new object();

    private static IObjectServer server;
    private static IObjectContainer container;

    private static IObjectServer Server {
        get {
            lock (serverLock) {
                if (server == null)
                    server = Db4oFactory.OpenServer(ConfigurationManager.AppSettings["DatabaseFilePath"], 0);
                return server;
            }
        }
    }

    private static IObjectContainer Container {
        get {
            lock (containerLock) {
                if (container == null)
                    container = Server.OpenClient();
                return container;
            }
        }
    }

    public IQueryable<T> Find<T>(Func<T, bool> predicate) {
        return (from T t in Container where predicate(t) select t).AsQueryable();
    }

    public IQueryable<T> Find<T>() {
        return (from T t in Container select t).AsQueryable();
    }

    public ValidationResult Save(IValidatable item) {
        var validationResult = item.Validate();
        if (!validationResult.IsValid) return validationResult;
        Container.Store(item);
        return validationResult;
    }

    public void Delete(object item) {
        Container.Delete(item);
    }

    public void Dispose() {
        Server.Close();
        Container.Close();
    }
}
+1  A: 

Hi!

I think you are missing the commit statement in your Save method.

Goran

Goran