From 07fe826f668a9633deb63065d9dadaba125243a7 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 17 Apr 2022 19:05:28 +0800 Subject: [PATCH] Update unit test --- .../SqlServerTest/SqlServerTest.csproj | 1 + Src/Asp.Net/SqlServerTest/UnitTest/Main.cs | 1 + .../SqlServerTest/UnitTest/UCustom018.cs | 129 ++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 Src/Asp.Net/SqlServerTest/UnitTest/UCustom018.cs diff --git a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj index d3b925018..a732b5554 100644 --- a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj +++ b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj @@ -94,6 +94,7 @@ + diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs b/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs index 34ce5477d..2cded3d6e 100644 --- a/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs +++ b/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs @@ -31,6 +31,7 @@ namespace OrmTest } public static void Init() { + UCustom018.Init(); UCustom017.Init(); UCustom016.Init(); UCustom015.Init(); diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UCustom018.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UCustom018.cs new file mode 100644 index 000000000..b96b5a61c --- /dev/null +++ b/Src/Asp.Net/SqlServerTest/UnitTest/UCustom018.cs @@ -0,0 +1,129 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SqlSugar; +namespace OrmTest +{ + public class UCustom018 + { + public static void Init() + { + var db = new SqlSugarScope(new SqlSugar.ConnectionConfig() + { + ConnectionString = Config.ConnectionString, + DbType = DbType.SqlServer, + IsAutoCloseConnection = true + }); + + + //建表 + if (!db.DbMaintenance.IsAnyTable("unit_Patent_License", false)) + { + db.CodeFirst.InitTables(); + } + + + + + //建表 + if (!db.DbMaintenance.IsAnyTable("Enterprise", false)) + { + db.CodeFirst.InitTables(); + } + db.DbMaintenance.TruncateTable(); + db.Insertable(new Patent_License() + { + Id = "1", + Licensee_Id = 1, + Licensor_Id = 1 + }).ExecuteCommand(); + db.Insertable(new UintEnterprise() + { + Id = 1, + Createtime = DateTime.Now, + Name = "" + }).ExecuteCommand(); + + + + RefAsync totalCount = 0; + + var data = db.Queryable() + + .LeftJoin((pl, db_licensor) => pl.Licensor_Id == db_licensor.Id) + + .LeftJoin((pl, db_licensor, db_licensee) => pl.Licensee_Id == db_licensee.Id) + + + .Select((pl, db_licensor, db_licensee) => new + { + + License = pl, + + LicensorId = (long?)db_licensor.Id, + + LicensorName = db_licensor.Name, + + LicenseeId = (long?)db_licensee.Id, + + LicenseeName = db_licensee.Name + + }) + + .ToPageListAsync(1, 2, totalCount).GetAwaiter().GetResult(); + + } + [SugarTable("unit_Patent_License")] + public class Patent_License + + { + + + + [SugarColumn(ColumnName = "id", IsPrimaryKey = true)] + + public string Id { get; set; } + + + + [SugarColumn(ColumnName = "licensor_id")] + + public long Licensor_Id { get; set; } + + + + + + [SugarColumn(ColumnName = "licensee_id")] + + public long Licensee_Id { get; set; } + + } + + public class UintEnterprise + + { + + [SugarColumn(ColumnName = "id", IsPrimaryKey = true)] + + public long Id { get; set; } + + + + + + [SugarColumn(ColumnName = "name")] + + public string Name { get; set; } + + + + [SugarColumn(ColumnName = "createtime")] + + public DateTime Createtime { get; set; } + + } + } +}