Esempio n. 1
0
        private Expression SingleFieldTwoArgOrCountMethod(string name, MethodCallExpression node)
        {
            WriteAppendAtFix(() =>
            {
                SQLWriter.Select();

                SQLWriter.Write(name);
                SQLWriter.OpenBrace();

                if (node.Arguments.Count > 1)
                {
                    base.Visit(node.Arguments[1]);
                }
                else
                {
                    SQLWriter.Write("1");
                }

                SQLWriter.CloseBrace();

                if (SQLWriter.IsUnion)
                {
                    SQLWriter.From();
                    SQLWriter.OpenBrace();
                }
            }, () => base.Visit(node.Arguments[0]));

            if (SQLWriter.IsUnion)
            {
                SQLWriter.CloseBrace();
                SQLWriter.WhiteSpace();

                SQLWriter.TableName("CTE_UNION");
            }

            return(node);
        }
Esempio n. 2
0
        private Expression VisitExecuteMethodCall(MethodCallExpression node)
        {
            switch (node.Method.Name)
            {
            case MethodCall.From:

                var value = (Func <ITableRegions, string>)node.Arguments[1].GetValueFromExpression();

                if (value == null)
                {
                    throw new DException("指定表名称不能为空!");
                }

                SetTableFactory(value);

                base.Visit(node.Arguments[0]);

                return(node);

            case MethodCall.Where:
                if (Behavior == ExecuteBehavior.Insert)
                {
                    throw new ExpressionNotSupportedException("插入语句不支持条件,请在查询器中使用条件过滤!");
                }

                return(MakeWhereNode(node));

            case MethodCall.Update:
                Behavior = ExecuteBehavior.Update;

                base.Visit(node.Arguments[0]);

                SQLWriter.AppendAt = 0;

                SQLWriter.Update();

                SQLWriter.Alias(GetOrAddTablePrefix(typeof(T)));

                SQLWriter.Set();

                base.Visit(node.Arguments[1]);

                SQLWriter.From();

                WriteTable(typeof(T));

                SQLWriter.AppendAt = -1;

                return(node);

            case MethodCall.Delete:
                Behavior = ExecuteBehavior.Delete;

                base.Visit(node.Arguments[0]);

                SQLWriter.AppendAt = 0;

                SQLWriter.Delete();

                SQLWriter.Alias(GetOrAddTablePrefix(typeof(T)));

                SQLWriter.From();

                WriteTable(typeof(T));

                SQLWriter.AppendAt = -1;

                return(node);

            case MethodCall.Insert:
                Behavior = ExecuteBehavior.Insert;

                base.Visit(node.Arguments[0]);

                SQLWriter.AppendAt = 0;
                SQLWriter.Insert();

                WriteTable(typeof(T));

                SQLWriter.AppendAt = -1;

                VisitBuilder(node.Arguments[1]);

                return(node);
            }

            throw new ExpressionNotSupportedException();
        }