public void ItShouldInitializeReferenceGrandchildCollectionsWhenFetched()
        {
            var root = EagerFetch.ThenFetchMany(EagerFetch.FetchMany(Session.Query <EmployerEntity>(), employerEntity => employerEntity.Employees), personEntity => personEntity.Cars)
                       .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 child 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");
        }
Exemple #3
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();
            }
        }