/// <summary> /// 将表达式所表示的SQL片断写入SQL构造器 /// </summary> public override void Write(ISqlBuilder builder) { if (base.Expression != null) { base._builder = builder; if (base._methodVisitor == null) { base._methodVisitor = _provider.CreateMethodCallVisitor(this); } _builder.AppendNewLine(); // SELECT 表达式解析 if (base.Expression.NodeType != ExpressionType.Constant) { base.Write(builder); } else { // if have no select syntax Type type = (base.Expression as ConstantExpression).Value as Type; this.VisitAllMember(type, "t0"); } // Include 表达式解析<导航属性> this.VisitInclude(); // 修剪尾部的空白字符 ColumnExpressionVisitor.TrimBuilder(_builder); } }
/// <summary> /// 将表达式所表示的SQL片断写入SQL构造器 /// </summary> public override void Write(ISqlBuilder builder) { base._builder = builder; if (base._methodVisitor == null) { base._methodVisitor = _provider.CreateMethodCallVisitor(this); } if (_statis != null) { Expression exp = _statis.DbExpressionType == DbExpressionType.Count ? Expression.Constant(1) : base.Expression; if (exp.NodeType == ExpressionType.Lambda) { exp = (exp as LambdaExpression).Body; } // q.Average(a => a); // 这种情况下g.Key 一定是单个字段,否则解析出来的SQL执行不了 if (exp.NodeType == ExpressionType.Parameter) { exp = _groupBy.Expressions[0]; } builder.Append(_statisMethods[_statis.DbExpressionType]); builder.Append("("); base.Visit(exp); builder.Append(")"); } //base.Visit(); }
/// <summary> /// 将表达式所表示的SQL片断写入SQL构造器 /// </summary> public void Write(ISqlBuilder builder, bool newLine) { if (_qOrder.Count > 0) { base._builder = builder; if (base._methodVisitor == null) { base._methodVisitor = _provider.CreateMethodCallVisitor(this); } if (newLine) { _builder.AppendNewLine(); } _builder.Append("ORDER BY "); //foreach (DbExpression qj in _qOrder) for (int i = 0; i < _qOrder.Count; i++) { this.Visit(_qOrder[i].Expressions[0]); if (_qOrder[i].DbExpressionType == DbExpressionType.OrderByDescending || _qOrder[i].DbExpressionType == DbExpressionType.ThenByDescending) { builder.Append(" DESC"); } if (i < _qOrder.Count - 1) { builder.Append(','); } } } }
/// <summary> /// 将表达式所表示的SQL片断写入SQL构造器 /// </summary> public override void Write(ISqlBuilder builder) { base._builder = builder; if (base._methodVisitor == null) { base._methodVisitor = _provider.CreateMethodCallVisitor(this); } foreach (DbExpression qj in _qJoin) { builder.AppendNewLine(); // [INNER/LEFT JOIN] if (qj.DbExpressionType == DbExpressionType.GroupJoin || qj.DbExpressionType == DbExpressionType.Join || qj.DbExpressionType == DbExpressionType.GroupRightJoin) { JoinType joinType = JoinType.InnerJoin; if (qj.DbExpressionType == DbExpressionType.GroupJoin) { joinType = JoinType.LeftJoin; } else if (qj.DbExpressionType == DbExpressionType.GroupRightJoin) { joinType = JoinType.RightJoin; } this.AppendJoinType(builder, joinType); this.AppendLfInJoin(builder, qj, _aliases); } else if (qj.DbExpressionType == DbExpressionType.SelectMany) { this.AppendJoinType(builder, JoinType.CrossJoin); this.AppendCrossJoin(builder, qj, _aliases); } } }
/// <summary> /// 将表达式所表示的SQL片断写入SQL构造器 /// </summary> public virtual void Write(ISqlBuilder builder) { _builder = builder; if (_methodVisitor == null) { _methodVisitor = _provider.CreateMethodCallVisitor(this); } this.Visit(_expression); }
/// <summary> /// 将表达式所表示的SQL片断写入SQL构造器 /// </summary> public override void Write(ISqlBuilder builder) { if (base.Expression != null) { base._builder = builder; if (base._methodVisitor == null) { base._methodVisitor = _provider.CreateMethodCallVisitor(this); } _builder.AppendNewLine(); // SELECT 表达式解析 if (base.Expression.NodeType == ExpressionType.Constant) { // if have no select syntax Type type = (base.Expression as ConstantExpression).Value as Type; this.VisitAllMember(type, "t0"); } else { base.Write(builder); } // Include 表达式解析<导航属性> this.VisitInclude(); // 去掉最后的空格和回车 if (_builder[_builder.Length - 1].ToString() != _provider.QuoteSuffix) { int space = Environment.NewLine.Length + 1; int index = _builder.Length - 1; while (_builder[index] == ' ') { space++; index--; } _builder.Length -= space; } } }