From b6edcde5068aaf9bbdd36e1ac85bd43f094fb7d0 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sat, 24 Jun 2023 15:07:16 +0800 Subject: [PATCH] Add unit test --- .../SqlServerTest/SqlServerTest.csproj | 1 + .../UnitTest/UnitUpdateOneToMany.cs | 84 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 Src/Asp.Net/SqlServerTest/UnitTest/UnitUpdateOneToMany.cs diff --git a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj index 960a1442b..aaeaa18a5 100644 --- a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj +++ b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj @@ -126,6 +126,7 @@ + diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UnitUpdateOneToMany.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UnitUpdateOneToMany.cs new file mode 100644 index 000000000..f2c162bf2 --- /dev/null +++ b/Src/Asp.Net/SqlServerTest/UnitTest/UnitUpdateOneToMany.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; + +using SqlSugar; + +namespace OrmTest +{ + public class UnitUpdateOneToMany + { + public static void Init() + { + var db = NewUnitTest.Db; + //建表 + db.CodeFirst.InitTables(); + db.DbMaintenance.TruncateTable(); + + //插入一级导航数据 + var country = new Country + { + Id = 1, + Name= "Test", + Provinces = new List { + new Province{ + Id = 1, + CountryId = 1, + IsDeleted= false, + }, + } + }; + + db.QueryFilter.AddTableFilter(it => it.IsDeleted == false); + //用例代码 + var result = db.InsertNav(country) + .Include(it => it.Provinces) + .ExecuteCommand();//用例代码 + + var list2 = db.Queryable().Includes(x => x.Provinces).ToList(); + country = new Country + { + Id = 1, + Name = "中国", + Provinces = new List { + new Province{ + Id = 2, + CountryId = 1, + IsDeleted= false, + }, + } + }; + //用例代码 + db.UpdateNav(country) + .Include(it => it.Provinces,new UpdateNavOptions() { OneToManyEnableLogicDelete=true }) + .ExecuteCommand();// + + var list3=db.Queryable().Includes(x => x.Provinces).ToList(); + db.QueryFilter.Clear(); + var list4 = db.Queryable().Includes(x => x.Provinces).ToList(); + + } + + + //建类 + [SugarTable("Unitaaa1Countradsfay")] + public class Country + { + [SugarColumn(IsPrimaryKey = true)] + public long Id { get; set; } + [SugarColumn(IsIgnore = true)] + [Navigate(NavigateType.OneToMany, nameof(Province.CountryId))] + public List Provinces { get; set; } + public string Name { get; set; } + } + [SugarTable("Unitaaa1Proviasdfance")] + public class Province + { + [SugarColumn(IsPrimaryKey = true)] + public long Id { get; set; } + public long CountryId { get; set; } + + public bool IsDeleted { get; set; } + } + + } +} \ No newline at end of file