Reputation: 1824
We are in the process of upgrading to RavenDB 2.5 and have run into a peculiar situation. One of our unit tests is suddenly failing, and for no obvious reason.
Here is some simple code to reproduce the issue:
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();
}
So, now we have two documents in the database, both with ExpirationTime = null. This is what happens when querying the database for these documents:
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);
}
The output from these queries are as follows:
1. Number of documents: 2
2. Number of documents: 0
3. Number of documents: 2
This doesn't seem correct to me... I would expect also number 2. to give 2.
I ran the same queries against a RavenDB server, and got the expected results, so it seems like this is an issue with the EmbeddableDocumentStore.
While testing this I also found some strange behavior when using the logical or operator in other cases. Sometimes using foo.HasValue
would give different result than foo != null
, but that might be related to the same issue.
Anyone else that have experienced this problem? Known bug?
Upvotes: 4
Views: 169
Reputation: 22956
This was a bug in RavenDB related to sorting on null fields. Fixed in the next build
Upvotes: 3