From e9b2c295bae447750ca867ef8b009719ab3ad3f1 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 27 Jun 2022 22:03:45 +0800 Subject: [PATCH] Add unit test --- .../SqlServerTest/UnitTest/UNavDynamic111N.cs | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UNavDynamic111N.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UNavDynamic111N.cs index 77075c4a8..9e12df543 100644 --- a/Src/Asp.Net/SqlServerTest/UnitTest/UNavDynamic111N.cs +++ b/Src/Asp.Net/SqlServerTest/UnitTest/UNavDynamic111N.cs @@ -13,8 +13,8 @@ namespace OrmTest { var db = NewUnitTest.Db; - db.CodeFirst.InitTables(); - db.DbMaintenance.TruncateTable(); + db.CodeFirst.InitTables(); + db.DbMaintenance.TruncateTable(); db.Insertable(new UnitaSchoolA() { SchoolId = 1, CityId = 1001001, School_Name = "北大" }).ExecuteCommand(); db.Insertable(new UnitaSchoolA() { SchoolId = 2, CityId = 2, School_Name = "清华" }).ExecuteCommand(); db.Insertable(new UnitaSchoolA() { SchoolId = 3, CityId = 3, School_Name = "青鸟" }).ExecuteCommand(); @@ -26,8 +26,18 @@ namespace OrmTest db.Insertable(new UnitaStudentA() { StudentId = 5, SchoolId = null, Name = "清华tom" }).ExecuteCommand(); db.Insertable(new UnitaStudentA() { StudentId = 6, SchoolId = 3, Name = "青鸟学生" }).ExecuteCommand(); - var list=db.Queryable() - .Includes(x => x.SchoolA).Where(x=>x.SchoolA.School_Name=="a").ToList(); + db.Insertable(new UnitaBookA() { BookId = 1, Names = "java", studenId = 1 }).ExecuteCommand(); + db.Insertable(new UnitaBookA() { BookId = 2, Names = "c#2", studenId = 2 }).ExecuteCommand(); + db.Insertable(new UnitaBookA() { BookId = 3, Names = "c#1", studenId = 2 }).ExecuteCommand(); + db.Insertable(new UnitaBookA() { BookId = 4, Names = "php", studenId = 3 }).ExecuteCommand(); + db.Insertable(new UnitaBookA() { BookId = 5, Names = "js", studenId = 4 }).ExecuteCommand(); + db.Insertable(new UnitaBookA() { BookId = 6, Names = "北大jack", studenId = 1 }).ExecuteCommand(); + + var list =db.Queryable() + .Includes(x => x.SchoolA).Where(x=>x.SchoolA.School_Name!=null).ToList(); + + var list2 = db.Queryable() + .Includes(x => x.Books).Where(x=>x.Books.Any()).ToList(); } public class UnitaStudentA { @@ -37,7 +47,9 @@ namespace OrmTest public int? SchoolId { get; set; } [Navigate(NavigateType.OneToOne, nameof(SchoolId),nameof(UnitaSchoolA.SchoolId))] public UnitaSchoolA SchoolA { get; set; } - + [Navigate(NavigateType.OneToMany, nameof(UnitaBookA.studenId),nameof(StudentId))] + public List Books { get; set; } + } public class UnitaSchoolA @@ -49,5 +61,13 @@ namespace OrmTest public string School_Name { get; set; } } + public class UnitaBookA + { + [SugarColumn(IsPrimaryKey = true)] + public int BookId { get; set; } + [SugarColumn(ColumnName = "Name")] + public string Names { get; set; } + public int studenId { get; set; } + } } }