我可能不明白ravendb中的“in”扩展方法是如何工作的。我认为它相当于sql世界中的in命令,例如where number in(1,2,3)。但它的行为很奇怪。

// i have 3 records - two with Normal severity, one with Low severity
using (var session = store.OpenSession())
{
    session.Store(new TestObject { Name = "o1", Severity = Severity.Normal });
    session.Store(new TestObject { Name = "o2", Severity = Severity.Low });
    session.Store(new TestObject { Name = "o3", Severity = Severity.Normal });
    session.SaveChanges();
}

// this writes the Low severity record, it seems correct
using (var session = store.OpenSession())
{
    var data = session.Query<TestObject>()
        .Where(o => o.Severity.In(new[] { Severity.Low }))
        .OrderBy(o => o.Name).ToList();
    data.ForEach(r => Console.WriteLine(r));
}

// this writes also the Low severity record, it still seems correct
using (var session = store.OpenSession())
{
    var data = session.Query<TestObject>()
        .Where(o => o.Severity.In(new[] { Severity.Low, Severity.High }))
        .OrderBy(o => o.Name).ToList();
    data.ForEach(r => Console.WriteLine(r));
}

// this writes all records, still seems correct
using (var session = store.OpenSession())
{
    var data = session.Query<TestObject>()
        .Where(o => o.Severity.In(
            new[] { Severity.High, Severity.Low, Severity.Normal }))
        .OrderBy(o => o.Name).ToList();
    data.ForEach(r => Console.WriteLine(r));
}

// but this does not write anything
// despite there are 2 records with Normal severity
using (var session = store.OpenSession())
{
    var data = session.Query<TestObject>()
        .Where(o => o.Severity.In(new[] { Severity.High, Severity.Normal }))
        .OrderBy(o => o.Name).ToList();
    data.ForEach(r => Console.WriteLine(r));
}

// and this does not write anything either,
// I just tried whether the order of values in the array matters
using (var session = store.OpenSession())
{
    var data = session.Query<TestObject>()
        .Where(o => o.Severity.In(new[] { Severity.Normal, Severity.High }))
        .OrderBy(o => o.Name).ToList();
    data.ForEach(r => Console.WriteLine(r));
}

或者我在ravendb/lucene引擎中发现了一个bug?
编辑
我发现了另一件奇怪的事。它与枚举成员的字母顺序有关。当我将severity.normal重命名为severity.a时,最后两个查询的行为正确并返回结果。
当我将severity.normal重命名为severity.la时,它仍然有效(因为lalow)时,它会中断,最后两个查询不再返回结果。原始样本不起作用,因为normal>low。但我还是想知道为什么会这样,因为这对我来说毫无意义。

最佳答案

您遇到了过时的索引,这就是为什么您会得到奇怪的结果。
您需要等待索引首先完成。

07-24 09:18