Beispiel #1
0
        // a ctor for .WhereExists support
        internal ConditionChainer(Chainer prev, INonSelectView nonSelectView, bool exists,
                                  PredicateGroup predicateGroup = null)
            : this(prev, predicateGroup)
        {
            CheckNullAndThrow(Arg(() => nonSelectView, nonSelectView));

            SelectChainer select = new SelectChainer((Chainer)nonSelectView, new Column[] { Designer.Null }, false);
            var           view   = new View(select, Query);

            Query.AddArguments(view.Query.Arguments.ToArray());

            Build = (buildContext, buildArgs) =>
            {
                string keyword = exists ? Text.Exists : Text.NotExists;

                var sql = Text.GenerateSql(100)
                          .NewLine(predicateGroup.Build(PredicateGroupType.Begin, Keyword)).S()
                          .Append(prev.ExpressionGroupType.IsBegin() ? Text.LeftBracket : null)
                          .Append(keyword).S()
                          .EncloseLeft()
                          .Append(view.Build(buildContext, buildArgs))
                          .EncloseRight()
                          .Append(prev.ExpressionGroupType.IsEnd() ? Text.RightBracket : null)
                          .Append(predicateGroup.Build(PredicateGroupType.End, null))
                          .S();

                TryThrow(buildContext);

                return(sql.ToString());
            };
        }
Beispiel #2
0
        internal ConditionChainer(Chainer prev, ScalarArgument argument1, ScalarArgument argument2, bool equality,
                                  PredicateGroup predicateGroup = null)
            : this(prev, predicateGroup)
        {
            CheckNullAndThrow(Arg(() => argument1, argument1));

            TryTake(argument1);
            TryTake(argument2);

            var expression = Expression.EqualitySimplifier(argument1, argument2, equality);

            Query.AddArguments(expression.Arguments);

            Build = (buildContext, buildArgs) =>
            {
                var sql = Text.GenerateSql(50)
                          .NewLine(predicateGroup.Build(PredicateGroupType.Begin, Keyword)).S()
                          .Append(prev.ExpressionGroupType.IsBegin() ? Text.LeftBracket : null)
                          .Append(expression.Build(buildContext, buildArgs))
                          .Append(prev.ExpressionGroupType.IsEnd() ? Text.RightBracket : null)
                          .Append(predicateGroup.Build(PredicateGroupType.End, null))
                          .S();

                buildContext.TryTakeException(expression.Exception);
                TryThrow(buildContext);

                return(sql.ToString());
            };
        }