Пример #1
0
        //string __QueryOrderBy = "";
        /// <summary>
        /// 设置排序
        /// 会重置原排序
        /// </summary>
        /// <typeparam name="TResult2"></typeparam>
        /// <param name="expression"></param>
        /// <param name="desc"></param>
        /// <returns></returns>
        public LambdaQueryResultSelect <TResult> OrderBy <TResult2>(Expression <Func <TResult, TResult2> > expression, bool desc = true)
        {
            var parameters = expression.Parameters.Select(b => b.Type).ToArray();
            var fields     = BaseQuery.GetSelectField(false, expression.Body, false, parameters).mapping;

            BaseQuery.SetOrder(fields.First(), desc);

            return(this);
        }
Пример #2
0
        /// <summary>
        /// 按TJoin排序
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="desc"></param>
        /// <returns></returns>
        public LambdaQueryJoin <T, TJoin> OrderBy <TResult>(Expression <Func <TJoin, TResult> > expression, bool desc = true)
        {
            var parameters = expression.Parameters.Select(b => b.Type).ToArray();
            //var innerType = typeof(TJoin);
            var fields = BaseQuery.GetSelectField(false, expression.Body, false, parameters).mapping;

            BaseQuery.SetOrder(fields.First(), desc);
            //if (!string.IsNullOrEmpty(BaseQuery.__QueryOrderBy))
            //{
            //    BaseQuery.__QueryOrderBy += ",";
            //}
            //BaseQuery.__QueryOrderBy += string.Format(" {0} {1}", fields.First().QueryField, desc ? "desc" : "asc");
            return(this);
        }