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); }
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); } }
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)); }