예제 #1
0
        /// <summary>
        /// 打印输出
        /// </summary>
        /// <param name="action">操作</param>
        /// <param name="description">描述</param>
        /// <param name="separator">分隔符</param>
        public static void Print(Action <ISqlBuilder> action, string description = "", string separator = "")
        {
            ISqlBuilder builder = new SqlServerBuilder(new DefaultEntityMatedata());

            action.Invoke(builder);
            if (!string.IsNullOrEmpty(separator))
            {
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.WriteLine($"--------------------------------[ {separator} ]----------------------------------");
                Console.WriteLine();
            }
            if (!string.IsNullOrEmpty(description))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(description);
            }
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(builder.ToSql());
            if (builder.GetParams() != null)
            {
                foreach (var item in builder.GetParams())
                {
                    Console.WriteLine(item.ToString());
                }
            }
            Console.WriteLine();
        }
예제 #2
0
        public void TestPage_2()
        {
            //结果
            var result = new String();

            result.AppendLine("Select * ");
            result.AppendLine("From [Test] ");
            result.AppendLine("Order By [a] ");
            result.Append("Offset @_p_0 Rows Fetch Next @_p_1 Rows Only");

            //执行
            var pager = new QueryParameter {
                Order = "a"
            };

            _builder.From("Test").Page(pager);

            //验证
            Assert.Equal(result.ToString(), _builder.ToSql());
            Assert.Equal(0, _builder.GetParams()["@_p_0"]);
            Assert.Equal(20, _builder.GetParams()["@_p_1"]);
        }
예제 #3
0
 public void TestWhere_1()
 {
     _builder.From("Test").Where("Name", "a");
     Assert.Equal($"Select * {Common.Line}From [Test] {Common.Line}Where [Name]=@_p__0", _builder.ToSql());
     Assert.Single(_builder.GetParams());
     Assert.Equal("a", _builder.GetParams()["@_p__0"]);
 }
예제 #4
0
        public void Test_3()
        {
            //结果
            var result = new String();

            result.AppendLine("Select [a3].[a],[a1].[b1],[a2].[b2] ");
            result.AppendLine("From [b] As [a2] ");
            result.AppendLine("Join [c] As [a3] On [a2].[d]=[a3].[e] ");
            result.Append("Where [b].[Name]=@_p_0");

            //执行
            _builder.Select("a,a1.b1,[a2].[b2]", "a3")
            .From("b", "a2")
            .Join("c", "a3").On("a2.d", "a3.[e]")
            .Where("b.Name", "abc");

            //验证
            Assert.Equal(result.ToString(), _builder.ToSql());
            Assert.Single(_builder.GetParams());
            Assert.Equal("abc", _builder.GetParams()["@_p_0"]);
        }