Ejemplo n.º 1
0
        /// <summary>
        /// 返回强类型结果选择
        /// </summary>
        /// <param name="resultSelector"></param>
        /// <returns></returns>
        public LambdaQueryResultSelect <TJoinResult, TJoinResult2> Select <TJoinResult2>(Expression <Func <T, TJoinResult, TJoinResult2> > resultSelector)
            where TJoinResult2 : class
        {
            var resultFields = BaseQuery.GetSelectField(true, resultSelector.Body, false, typeof(T), typeof(TJoin));
            var prefix1      = BaseQuery.GetPrefix(typeof(TJoinResult));
            var prefix2      = BaseQuery.GetPrefix(typeof(TJoin));

            foreach (var item in resultFields)
            {
                if (item.QueryFullScript.StartsWith(prefix1))
                {
                    item.QueryFullScript = item.QueryFullScript.Replace(prefix1, prefix2);
                }
            }
            BaseQuery.__QueryFields = resultFields;
            return(new LambdaQueryResultSelect <TJoinResult, TJoinResult2>(BaseQuery, resultSelector.Body));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 返回强类型结果选择
        /// </summary>
        /// <param name="resultSelector"></param>
        /// <returns></returns>
        public LambdaQueryResultSelect <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);
                }
            }
            //selectField.queryFieldString = BaseQuery.GetQueryFieldsString(resultFields);
            BaseQuery.SetSelectFiled(selectField);
            //BaseQuery.__QueryFields = resultFields;
            return(new LambdaQueryResultSelect <TJoinResult2>(BaseQuery, resultSelector.Body));
        }