标签: ndatabase

NDatabase在Order By上崩溃

我正在使用NDatabase来做一些非常简单的对象存储 - 基本上构建一个持久的工作队列.计划是创建一组对象,将它们保存到磁盘,然后在其中一个属性上读取它们.我无法使"已排序"部分工作 - NDatabase抛出异常.

这是我想要持久化的对象的超类型:

public abstract class Instruction: IComparable, IComparable<Instruction>
{
    public virtual DateTime Timestamp
    {
        get;
        set;
    }

    public int CompareTo(Instruction other)
    {
        if (this.Timestamp.Equals(other.Timestamp))
            return 0;

        return (this.Timestamp < other.Timestamp) ? -1 : 1;
    }

    public int CompareTo(object obj)
    {
        var other = obj as Instruction;
        return other == null ? -1 : this.CompareTo(other);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我创建对象存储的方式:

using (var odb = OdbFactory.Open(storeName))
{
    odb.IndexManagerFor<Instruction>().AddIndexOn("TimestampIndex", "Timestamp");
    foreach (var instruction in instructions)
    {
        odb.Store(instruction);
    }
    odb.IndexManagerFor<Instruction>().RebuildIndex("TimestampIndex");
}
Run Code Online (Sandbox Code Playgroud)

以下是如何在以后检索商店: …

c# ndatabase

1
推荐指数
1
解决办法
676
查看次数

标签 统计

c# ×1

ndatabase ×1