Example #1
0
        private Expression VisitExists(MethodCallExpression node, bool isNotWrap = false)
        {
            SQLWriter.Exists();

            SQLWriter.OpenBrace();

            bool join = buildJoin;

            buildJoin   = false;
            buildSelect = buildFrom = true;

            if (isNotWrap || node.Arguments.Count == 1)
            {
                UnWrap(() =>
                {
                    buildExists = true;

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

                    buildExists = false;

                    if (node.Arguments.Count > 1)
                    {
                        _whereSwitch.Execute();

                        WrapNot(() =>
                        {
                            base.Visit(node.Arguments[1]);
                        });
                    }
                });
            }
            else
            {
                UnWrap(() =>
                {
                    int length = 0;

                    WriteAppendAtFix(() =>
                    {
                        buildExists = true;

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

                        buildExists = false;
                    }, () =>
                    {
                        base.Visit(node.Arguments[1]);

                        length = SQLWriter.Length;
                    }, index =>
                    {
                        SQLWriter.AppendAt = SQLWriter.Length - (length - index);

                        _whereSwitch.Execute();
                    });
                });
            }

            SQLWriter.CloseBrace();

            buildJoin = join;

            return(node);
        }