Ejemplo n.º 1
0
        public void Test_Union_3()
        {
            //结果
            var result = new Str();

            result.AppendLine("(Select [a],[b] ");
            result.AppendLine("From [Test] ");
            result.AppendLine("Where [c]=@_p_1 ");
            result.AppendLine(") ");
            result.AppendLine("Union ");
            result.AppendLine("(Select [a],[b] ");
            result.AppendLine("From [Test2] ");
            result.AppendLine("Where [c]=@_p_0 ");
            result.AppendLine(") ");
            result.Append("Order By [a]");

            //执行
            var builder2 = _builder.New().Select("a,b").From("Test2").Where("c", 1).OrderBy("b");

            _builder.Select("a,b").From("Test").Where("c", 2).OrderBy("a").Union(builder2);

            //验证
            Assert.Equal(result.ToString(), _builder.ToSql());
            Assert.Equal(1, _builder.GetParams()["@_p_0"]);
            Assert.Equal(2, _builder.GetParams()["@_p_1"]);
        }
Ejemplo n.º 2
0
        public void Test_IsDeletedFilter_1()
        {
            //结果
            var result = new Str();

            result.AppendLine("Select [s].[StringValue] ");
            result.AppendLine("From [Sample5] As [s] ");
            result.AppendLine("Join [Sample2] As [s2] On [s].[IntValue]=[s2].[IntValue] ");
            result.Append("Where [s].[IsDeleted]=@_p_0");

            //执行
            _builder.Select <Sample5>(t => t.StringValue).From <Sample5>("s").Join <Sample2>("s2").On <Sample5, Sample2>((l, r) => l.IntValue == r.IntValue);

            //验证
            Output.WriteLine(_builder.ToSql());
            Assert.Equal(result.ToString(), _builder.ToSql());
        }
Ejemplo n.º 3
0
        public void Test_With_1()
        {
            //结果
            var result = new Str();

            result.AppendLine("With [Test] ");
            result.AppendLine("As (Select [a],[b] ");
            result.AppendLine("From [Test2])");
            result.AppendLine("Select [a],[b] ");
            result.Append("From [Test]");

            //执行
            var builder2 = _builder.New().Select("a,b").From("Test2");

            _builder.Select("a,b").From("Test").With("Test", builder2);

            //验证
            Assert.Equal(result.ToString(), _builder.ToSql());
        }
Ejemplo n.º 4
0
        public void Test_IgnoreFilter_3()
        {
            //结果
            var result = new Str();

            result.AppendLine("Select [s5].[StringValue] ");
            result.AppendLine("From [Sample5] As [s5] ");
            result.AppendLine("Join [Sample6] As [s6] On [s5].[IntValue]=[s6].[IntValue] ");
            result.AppendLine("Left Join [Sample7] As [s7] On [s6].[IntValue]=[s7].[IntValue] ");
            result.Append("Right Join [Sample8] As [s8] On [s7].[IntValue]=[s8].[IntValue]");

            //执行
            _builder.Select <Sample5>(t => t.StringValue)
            .From <Sample5>("s5")
            .Join <Sample6>("s6").On <Sample5, Sample6>((l, r) => l.IntValue == r.IntValue)
            .LeftJoin <Sample7>("s7").On <Sample6, Sample7>((l, r) => l.IntValue == r.IntValue)
            .RightJoin <Sample8>("s8").On <Sample7, Sample8>((l, r) => l.IntValue == r.IntValue)
            .IgnoreFilter <IsDeletedFilter>();

            //验证
            Output.WriteLine(_builder.ToSql());
            Assert.Equal(result.ToString(), _builder.ToSql());
        }