public void can_issue_queries_against_DateTime()
        {


            using (var session = theStore.LightweightSession())
            {
                var now = DateTime.UtcNow.ToUniversalTime();
                _output.WriteLine("now: " + now.ToString("o"));
                var testClass = new DateClass
                {
                    Id = Guid.NewGuid(),
                    DateTimeField = now
                };

                session.Store(testClass);

                session.Store(new DateClass
                {
                    DateTimeField = now.Add(5.Minutes())
                });

                session.Store(new DateClass
                {
                    DateTimeField = now.Add(-5.Minutes())
                });

                session.SaveChanges();

                var cmd = session.Query<DateClass>().Where(x => now >= x.DateTimeField)
                    .ToCommand();

                _output.WriteLine(cmd.CommandText);

                var sql = "select public.mt_immutable_timestamp(d.data ->> \'DateTimeField\') as time from public.mt_doc_dateclass as d";

                using (var reader = session.Connection.CreateCommand().Sql(sql).ExecuteReader())
                {
                    while (reader.Read())
                    {
                        _output.WriteLine("stored: " + reader.GetDateTime(0).ToString("o"));
                    }
                }


                session.Query<DateClass>().ToList().Each(x =>
                {
                    _output.WriteLine(x.DateTimeField.ToString("o"));
                });

                session.Query<DateClass>()
                    .Count(x => now >= x.DateTimeField).ShouldBe(2);

            }
        }
Exemple #2
0
        public void can_issue_queries_against_DateTime_with_camel_casing()
        {
            StoreOptions(_ => _.UseDefaultSerialization(casing: Casing.CamelCase));

            using (var session = theStore.LightweightSession())
            {
                var now = GenerateTestDateTime();
                _output.WriteLine("now: " + now.ToString("o"));
                var testClass = new DateClass
                {
                    Id            = Guid.NewGuid(),
                    DateTimeField = now
                };

                session.Store(testClass);

                session.Store(new DateClass
                {
                    DateTimeField = now.Add(5.Minutes())
                });

                session.Store(new DateClass
                {
                    DateTimeField = now.Add(-5.Minutes())
                });

                session.SaveChanges();

                var cmd = session.Query <DateClass>().Where(x => now >= x.DateTimeField)
                          .ToCommand();

                _output.WriteLine(cmd.CommandText);

                var sql = "select public.mt_immutable_timestamp(d.data ->> \'dateTimeField\') as time from public.mt_doc_dateclass as d";

                using (var reader = session.Connection.CreateCommand().Sql(sql).ExecuteReader())
                {
                    while (reader.Read())
                    {
                        _output.WriteLine("stored: " + reader.GetDateTime(0).ToString("o"));
                    }
                }


                session.Query <DateClass>().ToList().Each(x =>
                {
                    _output.WriteLine(x.DateTimeField.ToString("o"));
                });

                session.Query <DateClass>()
                .Count(x => now >= x.DateTimeField).ShouldBe(2);
            }
        }
Exemple #3
0
        public void can_issue_queries_against_DateTime_as_duplicated_column()
        {
            StoreOptions(_ => _.Schema.For <DateClass>().Duplicate(x => x.DateTimeField));

            using (var session = theStore.LightweightSession())
            {
                var now = GenerateTestDateTime();
                _output.WriteLine("now: " + now.ToString("o"));
                var testClass = new DateClass
                {
                    Id            = Guid.NewGuid(),
                    DateTimeField = now
                };

                session.Store(testClass);

                session.Store(new DateClass
                {
                    DateTimeField = now.Add(5.Minutes())
                });

                session.Store(new DateClass
                {
                    DateTimeField = now.Add(-5.Minutes())
                });

                session.SaveChanges();

                var cmd = session.Query <DateClass>().Where(x => now >= x.DateTimeField)
                          .ToCommand();

                _output.WriteLine(cmd.CommandText);


                session.Query <DateClass>().ToList().Each(x =>
                {
                    _output.WriteLine(x.DateTimeField.ToString("o"));
                });

                session.Query <DateClass>()
                .Count(x => now >= x.DateTimeField).ShouldBe(2);
            }
        }
        public void can_issue_queries_against_DateTime_as_duplicated_column()
        {
            StoreOptions(_ => _.Schema.For<DateClass>().Duplicate(x => x.DateTimeField));

            using (var session = theStore.LightweightSession())
            {
                var now = DateTime.UtcNow;
                _output.WriteLine("now: " + now.ToString("o"));
                var testClass = new DateClass
                {
                    Id = Guid.NewGuid(),
                    DateTimeField = now
                };

                session.Store(testClass);

                session.Store(new DateClass
                {
                    DateTimeField = now.Add(5.Minutes())
                });

                session.Store(new DateClass
                {
                    DateTimeField = now.Add(-5.Minutes())
                });

                session.SaveChanges();

                var cmd = session.Query<DateClass>().Where(x => now >= x.DateTimeField)
                    .ToCommand();

                _output.WriteLine(cmd.CommandText);


                session.Query<DateClass>().ToList().Each(x =>
                {
                    _output.WriteLine(x.DateTimeField.ToString("o"));
                });

                session.Query<DateClass>()
                    .Count(x => now >= x.DateTimeField).ShouldBe(2);

            }
        }