【问题标题】:Possible bug in RavenDB EmbeddableDocumentStoreRavenDB EmbeddableDocumentStore 中可能存在的错误
【发布时间】:2013-08-02 11:46:45
【问题描述】:

我们正在升级到 RavenDB 2.5 并遇到了特殊情况。 我们的一个单元测试突然失败了,原因不明。

这里有一些简单的代码来重现这个问题:

class Foo
{
    public Guid Id { get; private set; }
    public DateTime? ExpirationTime { get; set; }

    public Foo()
    {
        Id = Guid.NewGuid();
        ExpirationTime = null;
    }
}

var documentStore = new EmbeddableDocumentStore
    {
        RunInMemory = true,
        Conventions = { DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites }
    };
documentStore.Initialize();

using (var session = documentStore.OpenSession())
{
    session.Store(new Foo());
    session.Store(new Foo());
    session.SaveChanges();
}

所以,现在我们在数据库中有两个文档,它们的 ExpirationTime = null。 这是在数据库中查询这些文档时发生的情况:

using (var session = documentStore.OpenSession())
{
    var bar = session.Query<Foo>().Where(foo => foo.ExpirationTime == null).ToList();
    Console.WriteLine("1. Number of documents: {0}", bar.Count);

    bar = session.Query<Foo>().Where(foo => foo.ExpirationTime == null || 
                                     foo.ExpirationTime > DateTime.Now).ToList();
    Console.WriteLine("2. Number of documents: {0}", bar.Count);

    bar = session.Query<Foo>().Where(foo => foo.ExpirationTime == null | 
                                     foo.ExpirationTime > DateTime.Now).ToList();
    Console.WriteLine("3. Number of documents: {0}", bar.Count);        
}

这些查询的输出如下:

1. Number of documents: 2
2. Number of documents: 0
3. Number of documents: 2

这对我来说似乎不正确......我也希望数字 2. 给出 2。

我对 RavenDB 服务器运行了相同的查询,得到了预期的结果,所以这似乎是 EmbeddableDocumentStore 的问题。

在对此进行测试时,我还发现在其他情况下使用逻辑或运算符时会出现一些奇怪的行为。有时使用foo.HasValue 会得到与foo != null 不同的结果,但这可能与同一个问题有关。

还有其他人遇到过这个问题吗?已知错误?

【问题讨论】:

  • @NoLifeKing 我没有在示例代码中显示它,但我在单元测试时总是使用DefaultQueryingConsistency = ConsistencyOptions.QueryYourWritesWaitForNonStaleResultsAsOfLastWrite()。在升级到 Raven 2.5 之前,这也按预期工作。
  • 请将失败的单元测试发送到邮件列表
  • @AyendeRahien 我刚刚做了 :-)

标签: linq ravendb


【解决方案1】:

这是 RavenDB 中与空字段排序相关的错误。 在下一个版本中修复

【讨论】:

    猜你喜欢
    • 2018-04-13
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    • 2019-04-18
    • 2013-10-11
    • 2019-12-22
    • 2012-01-21
    • 2018-12-31
    相关资源
    最近更新 更多