Created
February 12, 2015 12:35
-
-
Save pellehenriksson/aff09d7976b5c4f5b527 to your computer and use it in GitHub Desktop.
RavenDB Invalid query result when using >= operator combined with In()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Sandbox | |
| { | |
| [Fact] | |
| public void Run_Forrest_Run() | |
| { | |
| var logger = LogManager.GetLogger(this.GetType().FullName); | |
| using (var store = new DocumentStore { ConnectionStringName = "Test" }) | |
| { | |
| store.Initialize(); | |
| store.RegisterListener(new NoStaleQueriesAllowed()); | |
| store.Initialize(); | |
| IndexCreation.CreateIndexes(typeof(Sandbox).Assembly, store); | |
| using (var session = store.OpenSession()) | |
| { | |
| session.Advanced.DocumentStore.DatabaseCommands.DeleteByIndex("Raven/DocumentsByEntityName", new IndexQuery { Query = "Tag:" + "Products" }, new BulkOperationOptions { AllowStale = true }); | |
| } | |
| using (var session = store.OpenSession()) | |
| { | |
| for (var i = 0; i < 10; i++) | |
| { | |
| session.Store(new Product { Name = "A-" + i, Category = "A", ReleaseDate = DateTime.Today }); | |
| } | |
| session.SaveChanges(); | |
| } | |
| using (var session = store.OpenSession()) | |
| { | |
| // THIS WILL RETURN 0 RESULTS | |
| var result = session.Query<Product>() | |
| .Where(x => x.Category.In("A")) | |
| .Where(x => x.ReleaseDate >= DateTime.Today) // <-- more or equal operation seems to be the problem | |
| .ToList(); | |
| Assert.Equal(10, result.Count); | |
| } | |
| using (var session = store.OpenSession()) | |
| { | |
| // THIS WILL RETURN EXPECTED 10 RESULTS | |
| var result = session.Query<Product>() | |
| .Where(x => x.Category.In("A")) | |
| .Where(x => x.ReleaseDate <= DateTime.Today) | |
| .ToList(); | |
| Assert.Equal(10, result.Count); | |
| } | |
| } | |
| } | |
| } | |
| public class Product | |
| { | |
| public string Id { get; set; } | |
| public string Name { get; set; } | |
| public string Category { get; set; } | |
| public DateTime? ReleaseDate { get; set; } | |
| } | |
| public class ProductIndex : AbstractIndexCreationTask<Product, ProductIndex.Result> | |
| { | |
| public ProductIndex() | |
| { | |
| this.Map = products => from p in products | |
| select new Result | |
| { | |
| Id = p.Id, | |
| Category = p.Category, | |
| Name = p.Name, | |
| ReleaseDate = p.ReleaseDate | |
| }; | |
| this.StoreAllFields(FieldStorage.Yes); | |
| } | |
| public class Result | |
| { | |
| public string Id { get; set; } | |
| public string Name { get; set; } | |
| public string Category { get; set; } | |
| public DateTime? ReleaseDate { get; set; } | |
| } | |
| } | |
| public class NoStaleQueriesAllowed : IDocumentQueryListener | |
| { | |
| public void BeforeQueryExecuted(IDocumentQueryCustomization queryCustomization) | |
| { | |
| queryCustomization.WaitForNonStaleResults(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment