From 26c38350dafc0b4e17d7b0c8a456354373f85c9a Mon Sep 17 00:00:00 2001
From: sunkaixuan <610262374@qq.com>
Date: Wed, 19 Jul 2023 23:38:15 +0800
Subject: [PATCH] Add unit test
---
.../SqlServerTest/SqlServerTest.csproj | 1 +
.../UnitTest/UnitUpdateOneToMany2.cs | 109 ++++++++++++++++++
2 files changed, 110 insertions(+)
create mode 100644 Src/Asp.Net/SqlServerTest/UnitTest/UnitUpdateOneToMany2.cs
diff --git a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj
index 4a5a73c14..27fda3ad3 100644
--- a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj
+++ b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj
@@ -130,6 +130,7 @@
+
diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UnitUpdateOneToMany2.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UnitUpdateOneToMany2.cs
new file mode 100644
index 000000000..547623ebc
--- /dev/null
+++ b/Src/Asp.Net/SqlServerTest/UnitTest/UnitUpdateOneToMany2.cs
@@ -0,0 +1,109 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using SqlSugar;
+
+namespace OrmTest
+{
+ public class UnitUpdateOneToMany2
+ {
+ public static void Init()
+ {
+ var db = NewUnitTest.Db;
+ //建表
+ db.CodeFirst.InitTables, Province>();
+ db.DbMaintenance.TruncateTable, Province>();
+
+ Test1(db);
+ Test2(db);
+ }
+
+ private static void Test1(SqlSugarClient db)
+ {
+ //插入一级导航数据
+ 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();
+
+
+ var ps = db.Queryable().ToList();
+ var ps2 = db.Queryable().ToList();
+ }
+
+ private static void Test2(SqlSugarClient db)
+ {
+ //插入一级导航数据
+ var country = new Country
+ {
+ Id = 2,
+ Name = "Test",
+ Provinces = new List {
+ new Province2{
+ Id = 2,
+ CountryId = 2,
+ 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();
+
+
+ var ps = db.Queryable().ToList();
+ var ps2 = db.Queryable().ToList();
+ }
+ //建类
+ [SugarTable("Unitaaa1CountradsfayXX")]
+ 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("Unitaaa1ProviasdfanceXX",Discrimator ="Type:1")]
+ public class Province
+ {
+ [SugarColumn(IsPrimaryKey = true)]
+ public long Id { get; set; }
+ public long CountryId { get; set; }
+
+ public bool IsDeleted { get; set; }
+ }
+
+ [SugarTable("Unitaaa1ProviasdfanceXX", Discrimator = "Type:2")]
+ public class Province2
+ {
+ [SugarColumn(IsPrimaryKey = true)]
+ public long Id { get; set; }
+ public long CountryId { get; set; }
+
+ public bool IsDeleted { get; set; }
+ }
+ }
+}
\ No newline at end of file