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); } }
public JoinBlock(QueryBlock query, JoinType joinType, TableRef innerRef, StatementBlock on) { this.query = query; JoinType = joinType; InnerRef = innerRef; On = on; }
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); }
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"); }
public CteBlock(QueryBlock query) { this.query = query; }
public GroupBlock(QueryBlock queryBlock) { this.queryBlock = queryBlock; }
public FromBlock(QueryBlock query) { this.query = query; }
public WhereBlock(QueryBlock query) { _query = query; }
public TmpTableRef(QueryBlock parent, Type resultType, string name) : base(parent) { _resultType = resultType; _name = name; }
public QueryBlock InsertQuery(Expression expression) { var result = new QueryBlock(this, null, expression); queries.Insert(0, result); return result; }
public IntoBlock(QueryBlock query) { this._query = query; }
public SelectBlock(QueryBlock query) { this.queryBlock = query; }
protected static TableRef Create(QueryBlock query, ITable table) { if (table == null) throw new ArgumentNullException(nameof(table)); return new TableRef(query) { _table = table }; }
protected TableRef(QueryBlock parent) { Parent = parent; }
public DummyRef(QueryBlock parent, string name) : base(parent) { this.name = name; }
public QueryBlock AddQuery(Expression expresion) { var result = new QueryBlock(this, null, expresion); queries.Add(result); return result; }
public OrderBlock(QueryBlock queryBlock) { this.queryBlock = queryBlock; }
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); }