public void ItShouldInitializeReferenceEntitiesWhenFetched() {
            var root = EagerFetch.Fetch(Session.Query<CarEntity>(), personEntity => personEntity.Owner).FirstOrDefault();
            root.Should().NotBeNull();

            NHibernateUtil.IsInitialized(root.Owner).Should().BeTrue("Owner should be initialized");
            SessionFactory.Statistics.EntityFetchCount.Should().Be(0, "nothing should have been lazy-loaded");
            SessionFactory.Statistics.PrepareStatementCount.Should().Be(1, "there should have been one query");
        }
        public void ItShouldInitializeReferenceGrandchildCollectionsWhenFetched() {
            var root = EagerFetch.ThenFetchMany(EagerFetch.Fetch(Session.Query<CarEntity>(), personEntity => personEntity.Owner), childEntity => childEntity.Pets)
                              .FirstOrDefault();
            root.Should().NotBeNull();

            NHibernateUtil.IsInitialized(root.Owner).Should().BeTrue("Owner should be initialized");
            NHibernateUtil.IsInitialized(root.Owner.Pets).Should().BeTrue("Owner.Pets should be initialized");
            SessionFactory.Statistics.EntityFetchCount.Should().Be(0, "northing should have been lazy-loaded");
            SessionFactory.Statistics.CollectionFetchCount.Should()
                          .Be(0, "the children collections should have been eager-loaded");
            SessionFactory.Statistics.PrepareStatementCount.Should().Be(1, "there should have been one query");
        }
        public void ItShouldEagerLoadReferenceCollectionsWhenFetched()
        {
            var root = EagerFetch.FetchMany(Session.Query <EmployerEntity>(), employerEntity => employerEntity.Employees).FirstOrDefault();

            root.Should().NotBeNull();

            var name = root.Employees.First().Name;

            NHibernateUtil.IsInitialized(root.Employees).Should().BeTrue("Employees should be initialized");
            SessionFactory.Statistics.EntityFetchCount.Should().Be(0, "the Employees should have been eager-loaded");
            SessionFactory.Statistics.CollectionFetchCount.Should()
            .Be(0, "the Employees collection should have been eager-loaded");
            SessionFactory.Statistics.PrepareStatementCount.Should().Be(1, "there should have been one query");
        }
        public void ItShouldInitializeReferenceCollectionsWhenFetched()
        {
            var employerEntities = Session.Query <EmployerEntity>();
            var fetchRequest     = EagerFetch.FetchMany(employerEntities, personEntity => personEntity.Employees);
            var root             = fetchRequest.FirstOrDefault();

            root.Should().NotBeNull();

            NHibernateUtil.IsInitialized(root.Employees).Should().BeTrue("Employees should be initialized");
            SessionFactory.Statistics.EntityFetchCount.Should().Be(0, "nothing should have been lazy-loaded");
            SessionFactory.Statistics.CollectionFetchCount.Should()
            .Be(0, "the Employees collection should have been eager-loaded");
            SessionFactory.Statistics.PrepareStatementCount.Should().Be(1, "there should have been one query");
        }
Exemple #5
0
        public virtual void RemoveFile(Guid fileId, int version, bool doNotCheckVersion = false)
        {
            var file = EagerFetch.FetchMany(repository
                                            .AsQueryable <MediaFile>(f => f.Id == fileId), f => f.AccessRules)
                       .FirstOrDefault();

            if (file == null)
            {
                throw new CmsException(string.Format("A file was not found by given id={0}", fileId));
            }

            try
            {
                if (file.IsUploaded.HasValue && file.IsUploaded.Value)
                {
                    Task.Factory
                    .StartNew(() => { })
                    .ContinueWith(task =>
                    {
                        storageService.RemoveObject(file.FileUri);
                    })
                    .ContinueWith(task =>
                    {
                        storageService.RemoveFolder(file.FileUri);
                    });
                }
            }
            finally
            {
                if (!doNotCheckVersion)
                {
                    file.Version = version;
                }
                file.AccessRules.ToList().ForEach(file.RemoveRule);
                repository.Delete(file);
                unitOfWork.Commit();
            }
        }
Exemple #6
0
 public void ItShouldUseTheFakeFetchingProviderWhenSet()
 {
     EagerFetch.Current().Should().BeOfType <FakeFetchingProvider>();
 }
 public void ItShouldUseTheDefaultFetchingProviderWhenSet()
 {
     EagerFetch.Current().Should().BeOfType <NHibernateFetchingProvider>();
 }