예제 #1
0
 private void Clear()
 {
     SqlBuilder.Clear();
     JoinRelations.Clear();
     WhereClause.Clear();
     Parameters.Clear();
     OrderByFields.Clear();
     GroupByFields.Clear();
     SelectFields.Clear();
 }
예제 #2
0
        protected override Expression VisitMethodCall(MethodCallExpression methodExp)
        {
            if (methodExp.Method.Name == "OrderByDescending" || methodExp.Method.Name == "ThenByDescending")
            {
                OrderByFields.Clear();
                OrderBy = "DESC";
                Expression obj = this.Visit(((LambdaExpression)methodExp.Arguments[1]).Body);
                OrderByFieldsStack.Insert(0, OrderByFields.ToString().TrimEnd(','));
                OrderByFields.Clear();
                if (methodExp.Arguments[0].NodeType == ExpressionType.Call)
                {
                    this.Visit(methodExp.Arguments[0]);
                }
                return(methodExp);
            }
            else if (methodExp.Method.Name == "OrderBy" || methodExp.Method.Name == "ThenBy")
            {
                OrderByFields.Clear();
                OrderBy = "ASC";
                Expression obj = this.Visit(((LambdaExpression)methodExp.Arguments[1]).Body);
                OrderByFieldsStack.Insert(0, OrderByFields.ToString().TrimEnd(','));
                OrderByFields.Clear();
                if (methodExp.Arguments[0].NodeType == ExpressionType.Call)
                {
                    this.Visit(methodExp.Arguments[0]);
                }
                return(methodExp);
            }
            else
            {
                Expression obj    = this.Visit(methodExp.Object);
                object     result = Expression.Lambda(methodExp).Compile().DynamicInvoke();
                var        r      = Expression.Constant(result, methodExp.Method.ReturnType);
                this.Visit(r);
                return(r);
            }

            throw new NotSupportedException(string.Format("lambda表达式不支持使用此'{0}'方法", methodExp.Method.Name));
        }