gpt4 book ai didi

c# - RavenDb "In"运算符如何工作?

转载 作者:太空狗 更新时间:2023-10-29 20:24:44 24 4
gpt4 key购买 nike

我可能不明白 RavenDb 中的“In”扩展方法是如何工作的。我认为它相当于 SQL 世界中的 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) 时,它中断了,最后两个查询不再返回结果。原始样本不起作用,因为正常 > 低。但我仍然想知道为什么会这样,因为这对我来说毫无意义。

最佳答案

您遇到了陈旧的索引,这就是您得到奇怪结果的原因。您需要先等待索引完成。

关于c# - RavenDb "In"运算符如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13545663/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com