Exemple #1
0
        public void CanLoadLazyBelongsToOutsideOfScope()
        {
            ActiveRecordStarter.Initialize(GetConfigSource(), typeof(ScopelessLazy), typeof(ObjectWithLazyAssociation), typeof(VeryLazyObject2));

            Recreate();

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

            var obj = new ObjectWithLazyAssociation();
            obj.LazyObj = lazy;
            ActiveRecordMediator.Save(obj);

            var objFromDb = (ObjectWithLazyAssociation) ActiveRecordMediator.FindByPrimaryKey(typeof(ObjectWithLazyAssociation), obj.Id);
            Assert.False(NHibernate.NHibernateUtil.IsInitialized(objFromDb.LazyObj));
            Assert.AreEqual("test", objFromDb.LazyObj.Title);
            Assert.True(NHibernate.NHibernateUtil.IsInitialized(objFromDb.LazyObj));
        }
        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);
            }
        }