c# – RavenDb“In”运算符如何工作?

前端之家收集整理的这篇文章主要介绍了c# – RavenDb“In”运算符如何工作?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我可能不明白RavenDb中的“In”扩展方法是如何工作的.我认为它相当于sql世界中的IN命令,例如数字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引擎中发现了一个错误

编辑

我发现了另一件奇怪的事.它必须按照枚举成员的字母顺序执行某些操作.当我将Severity.Normal重命名为Severity.A时,最后两个查询的行为正确并返回结果.
当我将Severity.Normal重命名为Severity.La时,它仍然有效(因为La< Low).但是当我将Severity.Normal重命名为Severity.Lu(Lu> Low)时,它会中断并且最后两个查询不再返回结果.原始样本不起作用,因为正常>低.但我仍然想知道为什么会这样,因为它对我没有意义.

解决方法

你正在遇到陈旧的索引,这就是你得到奇怪结果的原因. 您需要等待索引首先完成.
原文链接:https://www.f2er.com/csharp/101001.html

猜你在找的C#相关文章