Exemple #1
0
        /// <summary>
        /// 将源数据对象转换到新对象中
        /// </summary>
        /// <typeparam name="TSource">原数据实体类型</typeparam>
        /// <typeparam name="TResult">返回值的新实体类型</typeparam>
        /// <param name="queryable">查询对象</param>
        /// <param name="expression">给新实体赋值的表达式</param>
        /// <returns>Queryable</returns>
        public static Queryable <TResult> Select <TSource, TResult>(this Queryable <TSource> queryable, Expression <Func <TSource, TResult> > expression)
        {
            var type   = typeof(TSource);
            var expStr = expression.ToString();
            Queryable <TResult> reval = new Queryable <TResult>()
            {
                DB             = queryable.DB,
                OrderByValue   = queryable.OrderByValue,
                Params         = queryable.Params,
                Skip           = queryable.Skip,
                Take           = queryable.Take,
                WhereValue     = queryable.WhereValue,
                TableName      = queryable.TableName,
                GroupByValue   = queryable.GroupByValue,
                JoinTableValue = queryable.JoinTableValue
            };

            if (queryable.JoinTableValue.IsValuable())
            {
                ResolveSelect.GetResult <TResult>(expStr, reval, expression);
            }
            else
            {
                reval.SelectValue = expStr;
                ResolveSelect.GetResult <TResult>(reval, expression);
            }
            return(reval);
        }
Exemple #2
0
        /// <summary>
        /// 将源数据对象转换到新对象中
        /// </summary>
        /// <typeparam name="T">原数据实体类型</typeparam>
        /// <typeparam name="T2">原数据实体类型</typeparam>
        /// <typeparam name="T3">原数据实体类型</typeparam>
        /// <typeparam name="T4">原数据实体类型</typeparam>
        /// <typeparam name="T5">原数据实体类型</typeparam>
        /// <typeparam name="TResult">返回值的新实体类型</typeparam>
        /// <param name="queryable">查询对象</param>
        /// <param name="expression">给新实体赋值的表达式</param>
        /// <returns>Queryable</returns>
        public static Queryable <TResult> Select <T, T2, T3, T4, T5, TResult>(this Queryable <T> queryable, Expression <Func <T, T2, T3, T4, T5, TResult> > expression)
        {
            var expStr = expression.ToString();
            var type   = typeof(T);
            Queryable <TResult> reval = new Queryable <TResult>()
            {
                DB             = queryable.DB,
                OrderByValue   = queryable.OrderByValue,
                Params         = queryable.Params,
                Skip           = queryable.Skip,
                Take           = queryable.Take,
                WhereValue     = queryable.WhereValue,
                TableName      = queryable.TableName,
                GroupByValue   = queryable.GroupByValue,
                JoinTableValue = queryable.JoinTableValue
            };

            ResolveSelect.GetResult <TResult>(expStr, reval, expression);
            return(reval);
        }