예제 #1
0
		public void CanSaveAndLoadLazy()
		{
			ActiveRecordStarter.Initialize(GetConfigSource(),typeof(VeryLazyObject));
			Recreate();
			VeryLazyObject lazy = new VeryLazyObject();
			lazy.Title = "test";

			ActiveRecordMediator.Save(lazy);

			VeryLazyObject lazyFromDb = (VeryLazyObject)ActiveRecordMediator.FindByPrimaryKey(typeof(VeryLazyObject),lazy.Id);
			Assert.AreEqual("test", lazyFromDb.Title);

			lazyFromDb.Title = "test for update";
			ActiveRecordMediator.Update(lazyFromDb);

			lazyFromDb = (VeryLazyObject)ActiveRecordMediator.FindByPrimaryKey(typeof(VeryLazyObject), lazy.Id);
			Assert.AreEqual("test for update", lazyFromDb.Title);
		}
예제 #2
0
        public void CanAddLazyToObject() {
            ActiveRecordStarter.Initialize(GetConfigSource(), typeof(ObjectWithLazyAssociation),
                                           typeof(VeryLazyObject));

            Recreate();

            using (new SessionScope()) {
                var lazy = new VeryLazyObject();
                lazy.Title = "test";
                ActiveRecordMediator.Save(lazy);

                var lazyFromDb = (VeryLazyObject)ActiveRecordMediator.FindByPrimaryKey(typeof(VeryLazyObject), lazy.Id);
                var newObj = new ObjectWithLazyAssociation();
                newObj.LazyObj = lazyFromDb;
                ActiveRecordMediator.Create(newObj);
            }
        }
예제 #3
0
        public void LoadingLazyObjectOutsideOfScopeDoesInitializeIfNHByteCodeIsUsed() {
            ActiveRecordStarter.Initialize(GetConfigSource(), typeof(VeryLazyObject));

            Recreate();

            var lazy = new VeryLazyObject();
            lazy.Title = "test";
            ActiveRecordMediator.Save(lazy);

            var lazyFromDb = (VeryLazyObject)ActiveRecordMediator.FindByPrimaryKey(typeof(VeryLazyObject), lazy.Id);
            Assert.True(NHibernate.NHibernateUtil.IsInitialized(lazyFromDb));
        }