Exemple #1
0
 public override T Accept <T>(DbExpressionVisitor <T> visitor)
 {
     return(visitor.Visit(this));
 }
Exemple #2
0
        /// <summary>
        /// 访问表示 null 合并运算的节点 a ?? b
        /// </summary>
        /// <param name="b">二元表达式节点</param>
        /// <returns></returns>
        protected override Expression VisitCoalesce(BinaryExpression b)
        {
            // 例: a.Name ?? "TAN" => ISNULL(a.Name,'TAN')
            Expression left  = b.Left.NodeType == ExpressionType.Constant ? b.Right : b.Left;
            Expression right = b.Left.NodeType == ExpressionType.Constant ? b.Left : b.Right;

            _builder.Append("NVL(");
            _visitor.Visit(left);
            _builder.Append(",");
            _visitor.Visit(right);
            _builder.Append(')');

            return(b);
        }
 public Expression VisitProjection(ProjectionExpression proj)
 {
     return(_defaultVisitor.Visit(proj));
 }
        /// <summary>
        /// 访问表示 null 合并运算的节点 a ?? b
        /// </summary>
        /// <param name="b">二元表达式节点</param>
        protected override Expression VisitCoalesce(BinaryExpression b)
        {
            // 例: a.Name ?? "TAN" => ISNULL(a.Name,'TAN')

            _builder.Append("COALESCE(");
            _visitor.Visit(b.Left is ConstantExpression ? b.Right : b.Left);
            _builder.Append(", ");
            _visitor.Visit(b.Left is ConstantExpression ? b.Left : b.Right);
            _builder.Append(")");


            return(b);
        }
Exemple #5
0
        /// <summary>
        /// 访问 StartWidth 方法
        /// </summary>
        /// <param name="m">方法表达式</param>
        protected override Expression VisitStartsWith(MethodCallExpression m)
        {
            _visitor.Visit(m.Object);
            if (this.NotOperands != null && this.NotOperands.Contains(m))
            {
                _builder.Append(" NOT");
            }
            _builder.Append(" LIKE ");
            if (m.Arguments[0].CanEvaluate())
            {
                ColumnAttribute column  = null;
                bool            unicode = SqlServerUtils.IsUnicode(_visitedMark.Current, out column);
                string          value   = _constor.GetSqlValue(m.Arguments[0].Evaluate().Value, _builder.TranslateContext, column);
                if (!_builder.Parameterized && value != null)
                {
                    value = value.TrimStart('N').Trim('\'');
                }

                if (_builder.Parameterized)
                {
                    _builder.Append("(");
                    _builder.Append(value);
                    _builder.Append(" + '%')");
                }
                else
                {
                    if (unicode)
                    {
                        _builder.Append('N');
                    }
                    _builder.Append("'");
                    _builder.Append(value);
                    _builder.Append("%'");
                }
            }
            else
            {
                _builder.Append("(");
                _visitor.Visit(m.Arguments[0]);
                _builder.Append(" + '%')");
            }

            return(m);
        }