Ejemplo n.º 1
0
        public override DbExpression Visit(DbMethodCallExpression exp)
        {
            IMethodHandler methodHandler;

            if (MethodHandlers.TryGetValue(exp.Method.Name, out methodHandler))
            {
                if (methodHandler.CanProcess(exp))
                {
                    methodHandler.Process(exp, this);
                    return(exp);
                }
            }

            DbFunctionAttribute dbFunction = exp.Method.GetCustomAttribute <DbFunctionAttribute>();

            if (dbFunction != null)
            {
                string schema       = dbFunction.Schema;
                string functionName = string.IsNullOrEmpty(dbFunction.Name) ? exp.Method.Name : dbFunction.Name;

                if (!string.IsNullOrEmpty(schema))
                {
                    this.QuoteName(schema);
                    this._sqlBuilder.Append(".");
                }

                this.QuoteName(functionName);
                this._sqlBuilder.Append("(");

                string c = "";
                foreach (DbExpression argument in exp.Arguments)
                {
                    this._sqlBuilder.Append(c);
                    argument.Accept(this);
                    c = ",";
                }

                this._sqlBuilder.Append(")");

                return(exp);
            }

            if (exp.IsEvaluable())
            {
                DbParameterExpression dbParameter = new DbParameterExpression(exp.Evaluate(), exp.Type);
                return(dbParameter.Accept(this));
            }

            throw UtilExceptions.NotSupportedMethod(exp.Method);
        }
Ejemplo n.º 2
0
        public override DbExpression Visit(DbMethodCallExpression exp)
        {
            IMethodHandler methodHandler;
            if (MethodHandlers.TryGetValue(exp.Method.Name, out methodHandler))
            {
                if (methodHandler.CanProcess(exp))
                {
                    methodHandler.Process(exp, this);
                    return exp;
                }
            }

            if (exp.IsEvaluable())
            {
                DbParameterExpression dbParameter = new DbParameterExpression(exp.Evaluate(), exp.Type);
                return dbParameter.Accept(this);
            }

            throw UtilExceptions.NotSupportedMethod(exp.Method);
        }