Exemplo n.º 1
0
		public void BasicInclude()
		{
			using (var store = GetDocumentStore())
			{
				using (var session = store.OpenSession())
				{
					var user = new User
					           {
						           Id = "users/1",
								   AddressId = "addresses/1",
								   Name = "John"
					           };

					var address = new Address
					              {
						              Id = "addresses/1",
									  City = "New York",
									  Country = "USA",
									  Street = "Wall Street"
					              };

					session.Store(user);
					session.Store(address);

					session.SaveChanges();
				}

				using (var session = store.OpenSession())
				{
					Assert.Equal(0, session.Advanced.NumberOfRequests);

					var user = session
						.Include<User>(x => x.AddressId)
						.Load<User>("users/1");

					Assert.Equal(1, session.Advanced.NumberOfRequests);

					Assert.NotNull(user);
					Assert.Equal("John", user.Name);

					var address = session.Load<Address>(user.AddressId);

					Assert.Equal(1, session.Advanced.NumberOfRequests);

					Assert.Equal("New York", address.City);
				}
			}
		}
Exemplo n.º 2
0
        public async Task CanLoadWithInclude()
        {
            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenAsyncSession())
                {
                    var address = new Address { City = "London", Country = "UK" };
                    await session.StoreAsync(address);
                    await session.StoreAsync(new User { Name = "Adam", AddressId = session.Advanced.GetDocumentId(address) });

                    await session.SaveChangesAsync();
                }

                using (var session = store.OpenAsyncSession())
                {
                    var user = await session.Include<User>(x => x.AddressId).LoadAsync<User>("users/1");

                    Assert.Equal(1, session.Advanced.NumberOfRequests);

                    var address = await session.LoadAsync<Address>(user.AddressId);

                    Assert.Equal(1, session.Advanced.NumberOfRequests);
                    Assert.NotNull(address);
                    Assert.Equal("London", address.City);
                }

                using (var session = store.OpenAsyncSession())
                {
                    var user = await session.Include("AddressId").LoadAsync<User>("users/1");

                    Assert.Equal(1, session.Advanced.NumberOfRequests);

                    var address = await session.LoadAsync<Address>(user.AddressId);

                    Assert.Equal(1, session.Advanced.NumberOfRequests);
                    Assert.NotNull(address);
                    Assert.Equal("London", address.City);
                }
            }
        }