예제 #1
0
 public JoinBlock(QueryBlock query, JoinType joinType, TableRef innerRef, StatementBlock on)
 {
     this.query = query;
     JoinType = joinType;
     InnerRef = innerRef;
     On = on;
 }
예제 #2
0
        public void ApplyJoin(JoinType joinType, TableRef inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression membersSelector)
        {
            var left = new StatementBlock(query.QueryBatch, outerKeySelector.Body, new QueryMapWithLambdaParam(query.QueryMap, outerKeySelector.Parameters[0]));
            var right = new StatementBlock(query.QueryBatch, innerKeySelector.Body, new QueryMapWithLambdaParam(inner.QueryMap, innerKeySelector.Parameters[0]));
            Joins.Add(new JoinBlock(query, joinType, inner, new StatementBlock($"{left} = {right}")));

            var p1 = new QueryMapWithLambdaParam(query.QueryMap, membersSelector.Parameters[0]);
            var p2 = new QueryMapWithLambdaParam(inner.QueryMap, membersSelector.Parameters[1]);
            query.QueryMap = new MapTransformer(p1, p2).Transform(membersSelector.Body);
        }
예제 #3
0
        public void Inspect(Expression innerExpression, LambdaExpression key, LambdaExpression next)
        {
            topQuery = new QueryBlock(query.QueryBatch, query, innerExpression);
            topQuery.QueryMap.Add(new ColumnMap(new TypeMemberPath(lvl), new StatementBlock("1")));

            bottomQuery = new QueryBlock(null, query, null);
            bottomQuery.From.MainTable = new DummyRef(query, "cte");

            var baseQuery = TableRef.Create(bottomQuery, innerExpression);
            var resultType = typeof(RecursionEntry<>).MakeGenericType(baseQuery.ResultType);

            bottomQuery.QueryMap = new QueryMap(resultType, bottomQuery.From.MainTable.Alias);
            //bottomQuery.QueryMap.Add(new ColumnMap(new TypeMemberPath(lvl), new StatementBlock($"[{bottomQuery.From.MainTable.Alias}.{lvl}]")));

            CreateJoinExpressionToCte(baseQuery, key, next);

            query.QueryMap = new QueryMap();
            query.QueryMap.AddRange(baseQuery.QueryMap.RightShift(CtePropertyName));
            query.QueryMap.Add(new ColumnMap(new TypeMemberPath(lvl), new StatementBlock(lvl)));

            query.From.MainTable = new DummyRef(query, "cte");
        }
예제 #4
0
        /// <summary>
        /// select h.*, lvl + 1 as lvl
        /// from cte as c
        ///     inner join Hierarchy h on h.parentId = c.Id
        /// </summary>
        private void CreateJoinExpressionToCte(TableRef baseQuery, LambdaExpression key, LambdaExpression next)
        {
            var resultType = typeof(RecursionEntry<>).MakeGenericType(baseQuery.ResultType);
            var outter_p = Expression.Parameter(resultType);
            var inner_p = Expression.Parameter(baseQuery.ResultType);
            var cteInit = Expression.Bind(resultType.GetMember(CtePropertyName)[0], inner_p);

            var lvlPlusOne = Expression.Add(Expression.MakeMemberAccess(outter_p, resultType.GetMember(LevelPropertyName)[0]), Expression.Constant(1));
            var lvlInit = Expression.Bind(resultType.GetMember(LevelPropertyName)[0], lvlPlusOne);

            var memberInit = Expression.MemberInit(Expression.New(resultType), cteInit, lvlInit);
            bottomQuery.From.ApplyJoin(JoinType.Inner, baseQuery, ChangeToCteMemberAccess(resultType, next), key, Expression.Lambda(memberInit, outter_p, inner_p));
        }
예제 #5
0
 internal void CopyFrom(TableRef inner)
 {
     throw new NotImplementedException();
 }