예제 #1
0
        public void CanGetEmptyCollection()
        {
            using (var store = NewDocumentStore())
            {
                new CasinosSuspensionsIndex().Execute(store);

                using (var documentSession = store.OpenSession())
                {
                    var casino = new Casino("cities/1", "address", "name")
                    {
                        Suspensions = new List <Suspension>
                        {
                            new Suspension(DateTime.UtcNow, new List <Exemption>())
                        }
                    };
                    documentSession.Store(casino);
                    documentSession.SaveChanges();

                    var suspensions = documentSession.Query <CasinosSuspensionsIndex.IndexResult, CasinosSuspensionsIndex>().
                                      Customize(x => x.WaitForNonStaleResults()).
                                      Where(x => x.CityId == "cities/1").
                                      OrderByDescending(x => x.DateTime).
                                      Take(10).
                                      AsProjection <CasinosSuspensionsIndex.IndexResult>().
                                      ToList();

                    // note that suspensions[0].Exemptions will be null, because we don't have
                    // any values in the array, and we don't store empty arrays
                    Assert.NotEmpty(suspensions);
                    Assert.Null(suspensions.Single().Exemptions);
                }
            }
        }
예제 #2
0
        public void QueryById()
        {
            using (GetNewServer())
                using (
                    var documentStore = new DocumentStore()
                {
                    Url = "http://*****:*****@"
docs.Casinos
	.SelectMany(casino => casino.Comments, (casino, comment) => new {CityId = casino.CityId, CasinoId = casino.__document_id, Id = comment.Id, DateTime = comment.DateTime, Author = comment.Author, Text = comment.Text})"    ,
                        Stores =
                        {
                            { "CityId",   FieldStorage.Yes },
                            { "CasinoId", FieldStorage.Yes },
                            { "Id",       FieldStorage.Yes },
                            { "DateTime", FieldStorage.Yes },
                            { "Author",   FieldStorage.Yes },
                            { "Text",     FieldStorage.Yes }
                        }
                    });

                    var documentSession = documentStore.OpenSession();

                    var casino = new Casino("Cities/123456", "address", "name");
                    documentSession.Store(casino);
                    documentSession.SaveChanges();

                    var casinoFromDb = documentSession.Query <Casino>()
                                       .Customize(x => x.WaitForNonStaleResults())
                                       .Where(x => x.Id == casino.Id).Single();
                    Assert.NotNull(casinoFromDb);
                }
        }
예제 #3
0
		public void QueryById()
		{
			using (GetNewServer())
			using (
				var documentStore = new DocumentStore()
				{Url = "http://*****:*****@"
docs.Casinos
	.SelectMany(casino => casino.Comments, (casino, comment) => new {CityId = casino.CityId, CasinoId = casino.__document_id, Id = comment.Id, DateTime = comment.DateTime, Author = comment.Author, Text = comment.Text})",
					Stores =
				            {
				                {"CityId", FieldStorage.Yes},
				                {"CasinoId", FieldStorage.Yes},
				                {"Id", FieldStorage.Yes},
				                {"DateTime", FieldStorage.Yes},
				                {"Author", FieldStorage.Yes},
				                {"Text", FieldStorage.Yes}
				            }
				});

				var documentSession = documentStore.OpenSession();

				var casino = new Casino("Cities/123456", "address", "name");
				documentSession.Store(casino);
				documentSession.SaveChanges();

				var casinoFromDb = documentSession.Query<Casino>()
					.Customize(x=>x.WaitForNonStaleResults())
					.Where(x => x.Id == casino.Id).Single();
				Assert.NotNull(casinoFromDb);
			}
		}