Ejemplo n.º 1
0
        public void QuerySingleInclude()
        {
            var store = TestDocumentStore.Create(testOutputHelper: _testOutputHelper);

            using (var session = store.OpenSession())
            {
                var customer = new Customer("customer-1");
                session.Store(customer);

                var order = new Order(customer.Id);
                order.Complete();

                session.Store(order);
                session.SaveChanges();
            }

            _testOutputHelper.BeginTest("QuerySingleInclude");

            using (var session = store.QuerySession())
            {
                Customer customer = null;

                var firstOrder = session
                                 .Query <Order>()
                                 .Include <Customer>(order => order.CustomerId, value => customer = value)
                                 .FirstOrDefault(route => route.Status == OrderStatus.Completed);

                _testOutputHelper.WriteLine(firstOrder.ToString());
                _testOutputHelper.WriteLine(customer.ToString());
            }
        }
Ejemplo n.º 2
0
        public void QueryComplex()
        {
            var john     = "John";
            var pageSize = 20;
            var page     = 2;

            var store = TestDocumentStore.Create(testOutputHelper: _testOutputHelper);

            store.AddDinners(200);

            _testOutputHelper.BeginTest("QueryComplex");

            using (var session = store.QuerySession())
            {
                QueryStatistics stats;

                var dinners = session.Query <Dinner>()
                              .Stats(out stats)
                              .Where(x => x.HostedBy == john)
                              .OrderBy(x => x.EventDate)
                              .Skip(pageSize * page)
                              .Take(pageSize)
                              .Select(dinner => new
                {
                    dinner.Id,
                    dinner.Title,
                    Date = dinner.EventDate,
                    dinner.Address,
                    Host = dinner.HostedBy
                })
                              .ToList();

                _testOutputHelper
                .Write("TotalResults: " + stats.TotalResults)
                .Write("Dinners: " + dinners.Count)
                .NewLine()
                .WriteAsJson(dinners);
            }
        }