/// <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(); }
public void TestSelect_9() { _builder = new SqlServerBuilder(new DefaultEntityMatedata()); _builder.Select <Sample>(x => x.StringValue).Select <Sample2>(x => x.StringValue, "sample2StringValue") .From <Sample>("a") .Join <Sample2>("b").On <Sample, Sample2>((l, r) => l.StringValue == r.StringValue); Output.WriteLine(_builder.ToSql()); }
public void TestSelect_10() { //结果 var result = new String(); result.AppendLine("Select [Sample_Email],[Sample_IntValue] "); result.Append("From [b]"); //执行 _builder = new SqlServerBuilder(new TestEntityMatedata()); _builder.Select <Sample>(t => new object[] { t.Email, t.IntValue }).From("b"); //验证 Assert.Equal(result.ToString(), _builder.ToSql()); }
public void TestSelect_8() { //结果 var result = new String(); result.AppendLine("Select [s].[StringValue],[s].[IsDeleted] "); result.Append("From [Sample3] As [s]"); //执行 _builder = new SqlServerBuilder(new DefaultEntityMatedata()); _builder.Select <Sample3>().From <Sample3>("s"); //验证 Assert.Equal(result.ToString(), _builder.ToSql()); }
public void Test_RemoveSelect_1() { //结果 var result = new Str(); result.AppendLine("Select [s].[Description],[s].[DisplayName],[s].[StringValue],[s].[IntValue] "); result.Append("From [Sample2] As [s]"); //执行 _builder = new SqlServerBuilder(new DefaultEntityMatedata()); _builder.Select <Sample2>() .RemoveSelect <Sample2>(x => x.Display) .From <Sample2>("s"); //验证 Assert.Equal(result.ToString(), _builder.ToSql()); }
public void Test_Validate_1() { _builder.Select("a"); AssertHelper.Throws <InvalidOperationException>(() => _builder.ToSql()); }