Пример #1
0
		public void CanLoadForEntitiesWithInheritedIds()
		{
			//create some related products
			var category = new CategoryWithInheritedId {Name = "Fruit"};
			var product = new ProductWithInheritedId {CategoryWithInheritedId = category};

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

			ProductWithInheritedId restoredProductWithInheritedId;

			//restore the product from the db in another session so that 
			//the association is a proxy
			using (ISession session = OpenSession())
			{
				restoredProductWithInheritedId = session.Get<ProductWithInheritedId>(product.Id);
			}
			
			//verify that the category is a proxy
			Assert.IsFalse(NHibernateUtil.IsInitialized(restoredProductWithInheritedId.CategoryWithInheritedId));

			//we should be able to access the id of the category outside of the session
			Assert.AreEqual(category.Id, restoredProductWithInheritedId.CategoryWithInheritedId.Id);
		}
Пример #2
0
        public async Task CanLoadForEntitiesWithInheritedIdsAsync()
        {
            //create some related products
            var category = new CategoryWithInheritedId {
                Name = "Fruit"
            };
            var product = new ProductWithInheritedId {
                CategoryWithInheritedId = category
            };

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

            ProductWithInheritedId 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 <ProductWithInheritedId>(product.Id));
            }

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

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