Ejemplo n.º 1
0
		public void CanLoadForEntitiesWithTheirOwnIds()
		{
			//create some related products
			var category = new CategoryWithId { Name = "Fruit" };
			var product = new ProductWithId { CategoryWithId = category };

			using (ISession session = OpenSession())
			{
				using (ITransaction trans = session.BeginTransaction())
				{
					session.Save(category);
					session.Save(product);
					trans.Commit();
				}
			}

			ProductWithId restoredProductWithInheritedId;

			//restore the product from the db in another session so that 
			//the association is a proxy
			using (ISession session = OpenSession())
			{
				restoredProductWithInheritedId = session.Get<ProductWithId>(product.Id);
			}

			//verify that the category is a proxy
			Assert.IsFalse(NHibernateUtil.IsInitialized(restoredProductWithInheritedId.CategoryWithId));

			//we should be able to access the id of the category outside of the session
			Assert.AreEqual(category.Id, restoredProductWithInheritedId.CategoryWithId.Id);
		}
Ejemplo n.º 2
0
        public async Task CanLoadForEntitiesWithTheirOwnIdsAsync()
        {
            //create some related products
            var category = new CategoryWithId {
                Name = "Fruit"
            };
            var product = new ProductWithId {
                CategoryWithId = category
            };

            using (ISession session = OpenSession())
            {
                using (ITransaction trans = session.BeginTransaction())
                {
                    await(session.SaveAsync(category));
                    await(session.SaveAsync(product));
                    await(trans.CommitAsync());
                }
            }

            ProductWithId restoredProductWithInheritedId;

            //restore the product from the db in another session so that
            //the association is a proxy
            using (ISession session = OpenSession())
            {
                restoredProductWithInheritedId = await(session.GetAsync <ProductWithId>(product.Id));
            }

            //verify that the category is a proxy
            Assert.IsFalse(NHibernateUtil.IsInitialized(restoredProductWithInheritedId.CategoryWithId));

            //we should be able to access the id of the category outside of the session
            Assert.AreEqual(category.Id, restoredProductWithInheritedId.CategoryWithId.Id);
        }