Пример #1
0
        /// <summary>
        /// 选择TJoin关联值到对象内部索引
        /// 可调用多次,不要重复
        /// </summary>
        /// <param name="resultSelector"></param>
        /// <returns></returns>
        public LambdaQuery <T> SelectAppendValue <TJoinResult2>(Expression <Func <TJoinResult, TJoinResult2> > resultSelector)
        {
            //var innerType = typeof(TJoin);
            //if (BaseQuery.__QueryFields.Count == 0)
            //{
            //    BaseQuery.SelectAll();
            //}
            if (BaseQuery._CurrentSelectFieldCache == null)
            {
                BaseQuery.SelectAll(false);
            }
            var parameters  = resultSelector.Parameters.Select(b => b.Type).ToArray();
            var selectField = BaseQuery.GetSelectField(true, resultSelector.Body, true, parameters);
            var prefix1     = BaseQuery.GetPrefix(typeof(TJoinResult));
            var prefix2     = BaseQuery.GetPrefix(resultSelect.InnerType);

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

            //BaseQuery.__QueryFields.AddRange(resultFields);
            BaseQuery.SetSelectFiled(selectField);
            return(BaseQuery as LambdaQuery <T>);
        }
Пример #2
0
        /// <summary>
        /// 选择TJoin关联值到对象内部索引
        /// 可调用多次,不要重复
        /// </summary>
        /// <param name="resultSelector"></param>
        /// <returns></returns>
        public LambdaQuery <T> SelectAppendValue <TJoinResult2>(Expression <Func <TJoinResult, TJoinResult2> > resultSelector)
        {
            //var innerType = typeof(TJoin);
            if (BaseQuery.__QueryFields.Count == 0)
            {
                BaseQuery.SelectAll();
            }
            var resultFields = BaseQuery.GetSelectField(true, resultSelector.Body, true, 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.AddRange(resultFields);
            return(BaseQuery as LambdaQuery <T>);
        }