Пример #1
0
 public static TableRef Create(QueryBlock query, Expression expression)
 {
     if (expression.NodeType.In(ExpressionType.Constant, ExpressionType.MemberAccess))
     {
         var value = expression.GetValue();
         if (value is ITable)
         {
             return Create(query, (ITable)value);
         }
         else if (value is ITmpTable)
         {
             return CreateTmp(query, (IQueryable)value);
         }
         else if (value is IQueryable)
         {
             return new QueryBlock(query.QueryBatch, query, ((IQueryable)value).Expression);
         }
         else
         {
             throw new NotSupportedException();
         }
     }
     else
     {
         return new QueryBlock(query.QueryBatch, query, expression);
     }
 }
Пример #2
0
 public JoinBlock(QueryBlock query, JoinType joinType, TableRef innerRef, StatementBlock on)
 {
     this.query = query;
     JoinType = joinType;
     InnerRef = innerRef;
     On = on;
 }
Пример #3
0
        public QueryBlock(QueryBatch queryBatch, QueryBlock parent, Expression expression) : base(parent)
        {
            this.QueryBatch = queryBatch ?? parent.QueryBatch;

            Cte = new CteBlock(this);
            Select = new SelectBlock(this);
            Into = new IntoBlock(this);
            Where = new WhereBlock(this);
            From = new FromBlock(this);
            Group = new GroupBlock(this);
            Order = new OrderBlock(this);

            if (expression != null) Inspect(expression);
        }
Пример #4
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");
        }
Пример #5
0
 public CteBlock(QueryBlock query)
 {
     this.query = query;
 }
Пример #6
0
 public GroupBlock(QueryBlock queryBlock)
 {
     this.queryBlock = queryBlock;
 }
Пример #7
0
 public FromBlock(QueryBlock query)
 {
     this.query = query;
 }
Пример #8
0
 public WhereBlock(QueryBlock query)
 {
     _query = query;
 }
Пример #9
0
 public TmpTableRef(QueryBlock parent, Type resultType, string name) : base(parent)
 {
     _resultType = resultType;
     _name = name;
 }
Пример #10
0
 public QueryBlock InsertQuery(Expression expression)
 {
     var result = new QueryBlock(this, null, expression);
     queries.Insert(0, result);
     return result;
 }
Пример #11
0
 public IntoBlock(QueryBlock query)
 {
     this._query = query;
 }
Пример #12
0
 public SelectBlock(QueryBlock query)
 {
     this.queryBlock = query;
 }
Пример #13
0
        protected static TableRef Create(QueryBlock query, ITable table)
        {
            if (table == null) throw new ArgumentNullException(nameof(table));

            return new TableRef(query) { _table = table };
        }
Пример #14
0
 protected TableRef(QueryBlock parent)
 {
     Parent = parent;
 }
Пример #15
0
 public DummyRef(QueryBlock parent, string name)
     : base(parent)
 {
     this.name = name;
 }
Пример #16
0
 public QueryBlock AddQuery(Expression expresion)
 {
     var result = new QueryBlock(this, null, expresion);
     queries.Add(result);
     return result;
 }
Пример #17
0
 public OrderBlock(QueryBlock queryBlock)
 {
     this.queryBlock = queryBlock;
 }
Пример #18
0
 protected static TableRef CreateTmp(QueryBlock query, IQueryable tmpTable)
 {
     var tmpQuery = query.QueryBatch.InsertQuery(tmpTable.Expression);
     tmpQuery.Into.Name = query.QueryBatch.GenerateTempTableName();
     return new TmpTableRef(query, tmpTable.ElementType, tmpQuery.Into.Name);
 }