2
Vote

Constrain query does not work until after QueryAndExecute

description

Constrain query does not correctly work until after another query is done. Code below reproduces this issue.
using NDatabase;
using System;

namespace NDatabaseTest
{
    internal class Test
    {
        public Guid ID { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Test test = new Test();
            test.ID = Guid.NewGuid();
            Console.WriteLine("Stored ID: " + test.ID);

            // Open the database
            OdbFactory.Delete("test.db");
            using (var odb = OdbFactory.Open("test.db"))
            {
                // Store the object                
                odb.Store(test);
            }

            using (var odb = OdbFactory.Open("test.db"))
            {
                // Works if uncomment out line:
                //odb.QueryAndExecute<Test>();

                var query = odb.Query<Test>();
                query.Descend("ID").Constrain(test.ID).Equal();
                foreach (Test testRead in query.Execute<Test>())
                {
                    Console.WriteLine("Read ID: " + testRead.ID);
                }
            }

            Console.ReadKey();
        }
    }
}

comments