From dc4d08a731ee1d7ab80b14d2f052e32f06ce10c9 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sat, 30 Apr 2022 17:35:01 +0800 Subject: [PATCH] Update unit test --- Src/Asp.Net/PgSqlTest/PgSqlTest.csproj | 1 + Src/Asp.Net/PgSqlTest/UnitTest/Main.cs | 1 + Src/Asp.Net/PgSqlTest/UnitTest/UCustom08.cs | 80 +++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 Src/Asp.Net/PgSqlTest/UnitTest/UCustom08.cs diff --git a/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj b/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj index 9e71364e7..91a1a281d 100644 --- a/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj +++ b/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj @@ -99,6 +99,7 @@ + diff --git a/Src/Asp.Net/PgSqlTest/UnitTest/Main.cs b/Src/Asp.Net/PgSqlTest/UnitTest/Main.cs index ae29efe39..e71e0c1f0 100644 --- a/Src/Asp.Net/PgSqlTest/UnitTest/Main.cs +++ b/Src/Asp.Net/PgSqlTest/UnitTest/Main.cs @@ -31,6 +31,7 @@ namespace OrmTest } public static void Init() { + UCustom08.Init(); UCustom012.Init(); UCustom014.Init(); UCustom015.Init(); diff --git a/Src/Asp.Net/PgSqlTest/UnitTest/UCustom08.cs b/Src/Asp.Net/PgSqlTest/UnitTest/UCustom08.cs new file mode 100644 index 000000000..cce0424e7 --- /dev/null +++ b/Src/Asp.Net/PgSqlTest/UnitTest/UCustom08.cs @@ -0,0 +1,80 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SqlSugar; +namespace OrmTest +{ + public class UCustom08 + { + [SugarTable("Unit00UpdateTest")] + + public class UpdateTest + + { + + [SugarColumn(IsNullable = false, ColumnDescription = "主键", IsPrimaryKey = true)] + + public Guid Id { get; set; } + + + + [SugarColumn(IsNullable = false, ColumnDescription = "名称", ColumnDataType = "varchar(100)")] + + public string TN { get; set; } + + + + [SugarColumn(IsNullable = true, ColumnDescription = "测试")] + + public long? T1 { get; set; } + + } + + + + public static void Init() + + { + + var db = NewUnitTest.Db; + + db.Aop.OnError = (exp) =>//SQL报错 + + { + + string sql = exp.Sql; + + //exp.sql 这样可以拿到错误SQL + + }; + + db.DbMaintenance.CreateDatabase(); + + db.CodeFirst.InitTables(typeof(UpdateTest)); + + var id = Guid.NewGuid(); + + db.Insertable(new UpdateTest { Id = id, TN = "asdasd" }).ExecuteCommand(); + + var data = db.Queryable().Where(x => x.Id == id).First(); + + db.Updateable() + .SetColumns(x => new UpdateTest { T1 = (int)data.T1 }).Where(x => x.Id == id).ExecuteCommand(); + + db.Updateable() + .SetColumns(x => new UpdateTest { T1 = data.T1 }).Where(x => x.Id == id).ExecuteCommand(); + + + db.Updateable() + .SetColumns(x => new UpdateTest { T1 = 1 }).Where(x => x.Id == id).ExecuteCommand(); + + + Console.ReadKey(); + + } + } +} +