Exemplo n.º 1
0
        /// <summary>
        /// 创建关联一个强类型查询
        /// </summary>
        /// <typeparam name="TJoinResult"></typeparam>
        /// <param name="resultSelect"></param>
        /// <param name="expression"></param>
        /// <param name="joinType"></param>
        /// <returns></returns>
        public ILambdaQueryViewJoin <T, TJoinResult> Join <TJoinResult>(ILambdaQueryResultSelect <TJoinResult> resultSelect, Expression <Func <T, TJoinResult, bool> > expression, JoinType joinType = JoinType.Inner)
        {
            if (!resultSelect.BaseQuery.__FromDbContext)
            {
                throw new Exception("关联需要由LambdaQuery.CreateQuery创建");
            }
            var query2 = new LambdaQueryViewJoin <T, TJoinResult>(this, resultSelect);
            //var innerType = typeof(TSource);
            var innerType = resultSelect.InnerType;

            //var prefix1 = GetPrefix(innerType);
            var prefix2   = GetPrefix(typeof(TJoinResult));
            var typeQuery = new TypeQuery(innerType, prefix2);
            var baseQuery = resultSelect.BaseQuery;

            QueryParames.AddRange(baseQuery.QueryParames);

            string innerQuery = baseQuery.GetQuery();

            typeQuery.InnerQuery = innerQuery;
            string condition = FormatJoinExpression(expression.Body);

            AddInnerRelation(typeQuery, joinType, condition);
            return(query2);
        }
Exemplo n.º 2
0
        LambdaQuery <T> InnerSelect <TResult>(Expression <Func <T, TResult> > outField, LambdaQueryResultSelect <TResult> query, string type, string innerJoinSql = "")
        {
            if (!query.BaseQuery.__FromDbContext)
            {
                throw new CRLException("关联需要由LambdaQuery.CreateQuery创建");
            }
            var baseQuery = query.BaseQuery;

            QueryParames.AddRange(baseQuery.QueryParames);
            //foreach (var kv in baseQuery.QueryParames)
            //{
            //    QueryParames[kv.Key] = kv.Value;
            //}
            var query2 = baseQuery.GetQuery();

            return(InnerSelect(outField, query2, type));
        }