예제 #1
0
        /// <summary>
        /// Projects each element of a sequence into a new form.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of source.</typeparam>
        /// <typeparam name="TResult">The type of the value returned by selector.</typeparam>
        /// <param name="source">A CqlQuery&lt;TSource&gt; which after execution returns a sequence of values to invoke a transform function on.</param>
        /// <param name="selector">A transform function to apply to each element.</param>
        /// <returns>a CqlQuery&lt;TSource&gt; which after execution will return an IEnumerable&lt;TSource&gt; whose elements
        /// are the result of invoking the transform function on each element of source.
        /// To execute this CqlQuery use <c>Execute()</c> method.</returns>
        public static CqlQuery <TResult> Select <TSource, TResult>(this CqlQuery <TSource> source, Expression <Func <TSource, TResult> > selector)
        {
            Expression         expression = source.Expression;
            CqlQuery <TResult> result;

            if (typeof(TSource) != typeof(TResult))
            {
                //Its a client projection of an existent CqlQuery
                if (!(source is IClientProjectionCqlQuery))
                {
                    //The SELECT expression changed
                    expression = Expression.Call(null, CqlMthHelps.SelectMi, new[] { source.Expression, selector });
                    result     = new ClientProjectionCqlQuery <TSource, TResult>(expression, source, selector, true);
                }
                else
                {
                    //its a client projection of a client projection
                    //we should use the original source.Expression
                    result = new ClientProjectionCqlQuery <TSource, TResult>(expression, source, selector, true);
                }
            }
            else
            {
                expression = Expression.Call(null, CqlMthHelps.SelectMi, new[] { source.Expression, selector });
                //Its a mapper based projection
                result = (CqlQuery <TResult>)source.Table.CreateQuery <TResult>(expression);
            }
            source.CopyQueryPropertiesTo(result);
            return(result);
        }
예제 #2
0
        public static CqlQuery <TResult> Select <TGroup, TSource, TResult>(
            this CqlQuery <IGrouping <TGroup, TSource> > source,
            Expression <Func <IGrouping <TGroup, TSource>, TResult> > selector)
        {
            var expression = Expression.Call(null, CqlMthHelps.SelectMi, new[] { source.Expression, selector });
            var result     = new ClientProjectionCqlQuery <IGrouping <TGroup, TSource>, TResult>(
                expression, source, selector, false);

            result.CopyQueryPropertiesTo(result);
            return(result);
        }