Exemplo n.º 1
0
        /// <summary>
        /// 转换表达式
        /// </summary>
        /// <param name="expression">表达式</param>
        private void convertCall(MethodCallExpression expression)
        {
            MethodInfo method = expression.Method;

            if (method.ReflectedType == typeof(ExpressionCall))
            {
                switch (method.Name)
                {
                case "In": convertCall(expression, true); break;

                case "NotIn": convertCall(expression, false); break;

                case "Like":
                    System.Collections.ObjectModel.ReadOnlyCollection <System.Linq.Expressions.Expression> arguments = expression.Arguments;
                    convertIsSimple(arguments[0]);
                    SqlStream.SimpleWriteNotNull(" like ");
                    convertIsSimple(expression.Object);
                    ConstantConverter.ConvertLike(SqlStream, arguments[1].GetConstant(), true, true);
                    break;

                default:
                    SqlStream.SimpleWriteNotNull(method.Name);
                    SqlStream.Write('(');
                    if (expression.Arguments != null)
                    {
                        bool isNext = false;
                        foreach (Expression argumentExpression in expression.Arguments)
                        {
                            if (isNext)
                            {
                                SqlStream.Write(',');
                            }
                            Convert(argumentExpression);
                            isNext = true;
                        }
                    }
                    SqlStream.Write(')');
                    break;
                }
            }
            else if (IsStringContains(method))
            {
                convertIsSimple(expression.Object);
                SqlStream.SimpleWriteNotNull(" like ");
                ConstantConverter.ConvertLike(SqlStream, expression.Arguments[0].GetConstant(), true, true);
            }
            else
            {
                convertConstant(expression.GetConstant());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 转换表达式
        /// </summary>
        /// <param name="expression">表达式</param>
        private void convertCall(MethodCallExpression expression)
        {
            MethodInfo method = expression.Method;

            if (method.ReflectedType == typeof(ExpressionCall))
            {
                switch (method.Name)
                {
                case "In": convertCall(expression, true); break;

                case "NotIn": convertCall(expression, false); break;

                default:
                    SqlStream.SimpleWriteNotNull(method.Name);
                    SqlStream.Write('(');
                    if (expression.Arguments != null)
                    {
                        bool isNext = false;
                        foreach (Expression argumentExpression in expression.Arguments)
                        {
                            if (isNext)
                            {
                                SqlStream.Write(',');
                            }
                            Convert(argumentExpression);
                            isNext = true;
                        }
                    }
                    SqlStream.Write(')');
                    break;
                }
            }
            else
            {
                convertConstant(expression.GetConstant());
            }
        }