public void FindAll_With_StatelessSession()
        {
            var results = NHTool.FindAllStateless <Parent>();

            Assert.IsNotNull(results);
            Assert.IsTrue(results.Count > 0);
        }
        public void GetStateless_By_Id()
        {
            var id = parentsInDB[0].Id;

            var parentFromSession = Repository <Parent> .Get(id);

            var parentFromStateless = NHTool.GetStateless <Parent>(id, LockMode.None);

            Assert.IsNotNull(parentFromStateless);
            Assert.AreEqual(id, parentFromStateless.Id);

            Assert.AreEqual(parentFromSession, parentFromStateless);
        }
Beispiel #3
0
        /// <summary>
        /// 원본 객체를 대상 객체로 매핑합니다. <paramref name="additionalMapping"/>을 통해 추가적인 매핑을 수행할 수 있습니다.
        /// </summary>
        /// <typeparam name="TSource">원본 객체 형식</typeparam>
        /// <typeparam name="TTarget">대상 객체 형식</typeparam>
        /// <param name="sources">원본 객체 시퀀스</param>
        /// <param name="targetFactory">대상 객체 생성 Factory</param>
        /// <param name="mapOptions">매핑 옵션</param>
        /// <param name="additionalMapping">추가 매핑 함수</param>
        /// <param name="propertyExprsToExclude">매핑에서 제외할 속성 표현식</param>
        /// <returns>대상 객체 시퀀스</returns>
        public static IList <TTarget> MapEntitiesAsParallel <TSource, TTarget>(this IList <TSource> sources,
                                                                               Func <TTarget> targetFactory,
                                                                               MapPropertyOptions mapOptions,
                                                                               Action <TSource, TTarget> additionalMapping,
                                                                               params Expression <Func <TTarget, object> >[]
                                                                               propertyExprsToExclude)
        {
            if (IsDebugEnabled)
            {
                log.Debug("원본 엔티티[{0}] 컬렉션으로부터 대상 엔티티[{1}] 컬렉션으로 매핑을 수행합니다...",
                          typeof(TSource).Name, typeof(TTarget).Name);
            }

            targetFactory.ShouldNotBeNull("targetFactory");

            if (sources.Count == 0)
            {
                return(new List <TTarget>());
            }

            var propertyNamesToExclude =
                propertyExprsToExclude.Select(expr => ExpressionProcessor.FindMemberExpression(expr.Body)).ToList();

            ExcludeStatePropertyForStateEntity <TSource>(propertyNamesToExclude);

            // Source가 NHibernate 엔티티라면, Initialize를 통해, Lazy된 Proxy 값을 실제값으로 빌드합니다.
            //
            IList <TSource> initializedSources = sources;

            if (typeof(TSource).HasInterface(typeof(IStateEntity)))
            {
                if (IsDebugEnabled)
                {
                    log.Debug("원본 객체가 NHibernate Entity이므로, Initialize를 수행합니다...");
                }

                initializedSources = NHTool.InitializeEntities(sources, sources[0].IsDynamicProxy());
            }

            return
                (ObjectMapper
                 .MapObjectsAsParallel(initializedSources, targetFactory, mapOptions, additionalMapping,
                                       propertyNamesToExclude.ToArray())
                 .ToList());
        }
Beispiel #4
0
        public void CopyAndToTransientTest()
        {
            // Copy Parent
            //
            var parent = Repository <Parent> .Query().First();

            Assert.IsNotNull(parent);
            Assert.IsNotNull(parent.Children);
            parent.Children.Count.Should().Be.GreaterThan(0);

            var transient = NHTool.CopyAndToTransient(parent);

            transient.IsTransient.Should().Be.True();
            transient.IsSaved.Should().Be.False();
            transient.Id.Should().Be(default(Guid));

            transient.Name.Should().Be(parent.Name);

            // 일반 속성만 복사되고, Reference 정보는 복사하지 않습니다.
            transient.Children.Count.Should().Be(0);

            // Copy children
            //
            var child = parent.Children[0];

            child.Should().Not.Be.Null();
            child.Parent.Should().Be(parent);

            var transientChild = NHTool.CopyAndToTransient(child);

            transientChild.Should().Not.Be.Null();
            transientChild.Id.Should().Be(default(Guid));
            transientChild.IsSaved.Should().Be.False();
            transientChild.IsTransient.Should().Be.True();

            transientChild.Name.Should().Be(child.Name);

            transientChild.Parent.Should().Be.Null();
        }