Пример #1
0
        /// <summary>
        /// 按关联对象选择查询字段
        /// 可多次调用,不要重复
        /// </summary>
        /// <param name="resultSelector"></param>
        /// <returns></returns>
        public LambdaQueryJoin <T, TJoin> Select(Expression <Func <T, TJoin, object> > resultSelector)
        {
            //在关联两次以上,可调用以下方法指定关联对象获取对应的字段
            var resultFields = BaseQuery.GetSelectField(resultSelector.Body, false, typeof(T), typeof(TJoin));

            BaseQuery.__QueryFields.AddRange(resultFields);
            return(this);
        }
Пример #2
0
        /// <summary>
        /// 按关联对象选择查询字段
        /// 可多次调用,不要重复
        /// </summary>
        /// <param name="resultSelector"></param>
        /// <returns></returns>
        public LambdaQueryJoin <T, TJoin> Select <TResult>(Expression <Func <T, TJoin, TResult> > resultSelector)
        {
            //在关联两次以上,可调用以下方法指定关联对象获取对应的字段
            var parameters      = resultSelector.Parameters.Select(b => b.Type).ToArray();
            var selectFieldItem = BaseQuery.GetSelectField(true, resultSelector.Body, false, parameters);

            //BaseQuery.__QueryFields.AddRange(resultFields);
            //selectFieldItem.queryFieldString = ""; //re
            BaseQuery.SetSelectFiled(selectFieldItem);
            return(this);
        }
Пример #3
0
        /// <summary>
        /// 按关联对象选择查询字段
        /// 可多次调用,不要重复
        /// </summary>
        /// <param name="resultSelector"></param>
        /// <returns></returns>
        public LambdaQueryJoin <T, TJoin> Select <TResult>(Expression <Func <T, TJoin, TResult> > resultSelector)
        {
            //在关联两次以上,可调用以下方法指定关联对象获取对应的字段
            var parameters      = resultSelector.Parameters.Select(b => b.Type).ToArray();
            var selectFieldItem = BaseQuery.GetSelectField(true, resultSelector.Body, false, parameters);

            //BaseQuery.__QueryFields.AddRange(resultFields);
            selectFieldItem.queryFieldString   = "";
            BaseQuery._CurrentSelectFieldCache = selectFieldItem;
            BaseQuery._CurrentAppendSelectField.AddRange(selectFieldItem.fields);
            //BaseQuery.currentSelectFieldCache.queryFieldString += "," + BaseQuery.GetQueryFieldsString(resultFields);
            return(this);
        }
Пример #4
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);
        }
Пример #5
0
        /// <summary>
        /// 设置排序
        /// </summary>
        /// <typeparam name="TResult2"></typeparam>
        /// <param name="expression"></param>
        /// <param name="desc"></param>
        /// <returns></returns>
        public LambdaQueryResultSelect <T, TResult> OrderBy <TResult2>(Expression <Func <TResult, TResult2> > expression, bool desc = true)
        {
            var fields  = BaseQuery.GetSelectField(false, expression.Body, false, typeof(T));
            var orderBy = string.Format(" {0} {1}", fields.First().QueryField, desc ? "desc" : "asc");

            if (!string.IsNullOrEmpty(BaseQuery.__QueryOrderBy))
            {
                BaseQuery.__QueryOrderBy += ",";
            }
            BaseQuery.__QueryOrderBy += orderBy;
            return(this);
        }
        /// <summary>
        /// 返回强类型结果选择
        /// </summary>
        /// <param name="resultSelector"></param>
        /// <returns></returns>
        public ILambdaQueryResultSelect <TJoinResult2> Select <TJoinResult2>(Expression <Func <T, TJoinResult, TJoinResult2> > resultSelector)
            where TJoinResult2 : class
        {
            var parameters   = resultSelector.Parameters.Select(b => b.Type).ToArray();
            var selectField  = BaseQuery.GetSelectField(true, resultSelector.Body, false, parameters);
            var resultFields = selectField.mapping;
            var prefix1      = BaseQuery.GetPrefix(typeof(TJoinResult));
            var prefix2      = BaseQuery.GetPrefix(resultSelect.InnerType);

            //替换匿名前辍
            foreach (var item in resultFields)
            {
                if (item.QueryFull.Contains(prefix1))
                {
                    item.QueryFull = item.QueryFull.Replace(prefix1, prefix2);
                }
            }

            BaseQuery.SetSelectFiled(selectField);

            return(new LambdaQueryResultSelect <TJoinResult2>(BaseQuery, resultSelector.Body));
        }
Пример #7
0
        /// <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).fields;
            var orderBy    = string.Format(" {0} {1}", fields.First().QueryField, desc ? "desc" : "asc");

            if (!string.IsNullOrEmpty(__QueryOrderBy))
            {
                __QueryOrderBy += ",";
            }
            __QueryOrderBy          += orderBy;
            BaseQuery.__QueryOrderBy = __QueryOrderBy;
            return(this);
        }