开发者

Storing TimeSpan in db4o

开发者 https://www.devze.com 2023-01-22 20:24 出处:网络
I know that TimeSpan\'s are immutable. I have a object which contains a TimeSpan field. This field is updated frequently. Every time I update the object in the db, db4o updates the TimeSpan field. So

I know that TimeSpan's are immutable. I have a object which contains a TimeSpan field. This field is updated frequently. Every time I update the object in the db, db4o updates the TimeSpan field. So far, so good.

But the old TimeSpan structs are remaining in the db, so the db grows and grows. How can I prevent db4o for saving the others? I only need the TimeSpan currently held in this field.

class Test {
    TimeSpan _totalRuntime;
    void Work() {
        DateTime start = DateTime.Now;
        _totalRuntime = _totalRuntime.Add(DateTime.Now - start);
    }
}

// Open the db
IObjectContainer db = Db4oEmbedded.OpenFile(ConfigDb4O(), _db4OFilename);

public static IEmbeddedConfiguration ConfigDb4O() {
    IEmbeddedConfigurat开发者_StackOverflow中文版ion config = Db4oEmbedded.NewConfiguration();
    config.Common.Diagnostic.AddListener(new DiagnosticToConsole());
    return config;
}

db4o 7.12.132.14217 (.NET20)


As reported here db4o has some issues when updating value types that uses the "default typehandler" (you can see a typehandler as the piece of code in charge of marshaling objects to something that db4o can store).

We plan to fix this as soon as we find the time. Meanwhile I see at least 2 possible workarounds:

  1. Store TimeSpan.Ticks (a long) instead of the timespan itself, or
  2. Write a custom typehandler for TimeSpan (Harder, but not impossible).

PS: You can follow progress about this issue using the link above.

Best

Adriano

0

精彩评论

暂无评论...
验证码 换一张
取 消