Exemple #1
0
        /// <summary>
        ///     Populates the given <see cref="IResultStream{TDestination}" /> with the results, from the execution of
        ///     the given <see cref="IQueryableFlowQuery" />, in a streamed fashion.
        /// </summary>
        /// <typeparam name="TSource">
        ///     The <see cref="System.Type" /> of the source entity.
        /// </typeparam>
        /// <typeparam name="TDestination">
        ///     The <see cref="System.Type" /> of the result.
        /// </typeparam>
        /// <param name="query">
        ///     The query.
        /// </param>
        /// <param name="resultStream">
        ///     The <see cref="IResultStream{TDestination}" /> to stream the results into.
        /// </param>
        public static void SelectStream <TSource, TDestination>
        (
            IQueryableFlowQuery query,
            IResultStream <TDestination> resultStream
        )
        {
            Func <object, TDestination> converter = null;

            if (query.Constructor != null)
            {
                converter = ConstructionHelper.GetObjectByExpressionConverter <TDestination>(query.Constructor);
            }

            if (converter == null)
            {
                converter = x => (TDestination)x;
            }

            var streamer = new ResultStreamer <TDestination>(resultStream, converter);

            ICriteriaBuilder criteriaBuilder = GetCriteriaBuilder(query);

            ICriteria criteria = criteriaBuilder.Build <TSource, TDestination>(query);

            criteria.List(streamer);

            resultStream.EndOfStream();
        }
Exemple #2
0
        /// <summary>
        ///     Creates a regular <see cref="FlowQuerySelection{TDestination}" /> instance.
        /// </summary>
        /// <param name="query">
        ///     The query.
        /// </param>
        /// <typeparam name="TSource">
        ///     The <see cref="System.Type" /> of the source entity.
        /// </typeparam>
        /// <typeparam name="TDestination">
        ///     The <see cref="System.Type" /> of the result.
        /// </typeparam>
        /// <returns>
        ///     The created <see cref="FlowQuerySelection{TDestination}" /> instance.
        /// </returns>
        public static FlowQuerySelection <TDestination> SelectList <TSource, TDestination>(IQueryableFlowQuery query)
            where TSource : class
        {
            ICriteriaBuilder criteriaBuilder = GetCriteriaBuilder(query);

            ICriteria criteria = criteriaBuilder.Build <TSource, TDestination>(query);

            if (query.Constructor != null)
            {
                IEnumerable enumerable = query.IsDelayed
                    ? criteria.Future <object>()
                    : (IEnumerable)criteria.List();

                return(new FlowQuerySelection <TDestination>
                       (
                           () => ConstructionHelper.GetListByExpression <TDestination>(query.Constructor, enumerable)
                       ));
            }

            IEnumerable <TDestination> selection = query.IsDelayed
                ? criteria.Future <TDestination>()
                : criteria.List <TDestination>();

            // ReSharper disable once PossibleMultipleEnumeration
            return(new FlowQuerySelection <TDestination>(() => selection));
        }