From a30291aa3a5eba0e22b3130628f2e005a050c190 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Thu, 25 Aug 2022 20:52:37 +0800 Subject: [PATCH] Add unit test --- .../SqlServerTest/SqlServerTest.csproj | 1 + Src/Asp.Net/SqlServerTest/UnitTest/Main.cs | 1 + .../UnitTest/UnitManyToManyDeleteNav.cs | 143 ++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 Src/Asp.Net/SqlServerTest/UnitTest/UnitManyToManyDeleteNav.cs diff --git a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj index 3bed4f05e..edba3b0c7 100644 --- a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj +++ b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj @@ -97,6 +97,7 @@ + diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs b/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs index 31a9b9c84..9f25f290d 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() { + UnitManyToManyDeleteNav.Init(); UnitTestReturnPkList.Init(); UnitCustom12312.Init(); UnitEnum22.Init(); diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UnitManyToManyDeleteNav.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UnitManyToManyDeleteNav.cs new file mode 100644 index 000000000..746c87b46 --- /dev/null +++ b/Src/Asp.Net/SqlServerTest/UnitTest/UnitManyToManyDeleteNav.cs @@ -0,0 +1,143 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SqlSugar; +namespace OrmTest +{ + public class UnitManyToManyDeleteNav + { + + public static void Init() + { + var db = NewUnitTest.Db; + string businessKey = ""; + //建表 + if (!db.DbMaintenance.IsAnyTable("sys_schedule", false)) + { + db.CodeFirst.InitTables(); + db.CodeFirst.InitTables(); + db.CodeFirst.InitTables(); + } + //var userId = Core.App.CurrentUserFunc().UserId; + //var schIds = baseQueryable.Where(e => e.BusinessKey == businessKey).ToList()?.Select(it => it.Id).ToArray(); + //if (schIds == null) return; + //Db.Deleteable(x => schIds.Contains(x.ScheduleId) && x.SysUserId == userId).ExecuteCommand(); + //只删除关系 + db.DeleteNav(x => x.BusinessKey == businessKey) + .Include(x => x.SysUsers.Where(u => u.Id == 100).ToList()) // B表 + .ExecuteCommand(); + } + + } + /// + /// 创 建: + /// 日 期:2022/8/24 16:03:03 + /// 描 述:待办事项 + /// + + [SugarTable("sys_schedule11")] + public class ScheduleEntity + { + + [SugarColumn(IsPrimaryKey = true, ColumnName = "id")] + public long Id { get; set; } + /// + /// 0:未读,1:进行中,2:完成 + /// + [SugarColumn(ColumnDescription = "状态", ColumnName = "status", IsNullable = true )] + public int? Status { get; set; } + + + /// + /// 摘要() + /// + [SugarColumn(ColumnDescription = "摘要", ColumnName = "summary", IsNullable = true, Length = 255)] + public string Summary { get; set; } + + + /// + /// 内容() + /// + [SugarColumn(ColumnDescription = "内容", ColumnName = "content", IsNullable = true, Length = 255)] + public string Content { get; set; } + + + /// + /// 路由() + /// + [SugarColumn(ColumnDescription = "路由", ColumnName = "route", IsNullable = true, Length = 255)] + public string Route { get; set; } + + + + /// + /// 路由参数() + /// + [SugarColumn(ColumnDescription = "路由参数", ColumnDataType = "text", ColumnName = "routingParameters", IsNullable = true )] + public string RoutingParameters { get; set; } + + + /// + /// 业务Key() + /// + [SugarColumn(ColumnDescription = "业务Key", ColumnName = "businessKey", IsNullable = true, Length = 255)] + public string BusinessKey { get; set; } + + /// + /// 系统用户 + /// + [Navigate(typeof(Schedule_SysUser_Mapping), nameof(Schedule_SysUser_Mapping.ScheduleId), nameof(Schedule_SysUser_Mapping.SysUserId))]//注意顺序 + public List SysUsers { get; set; } + + } + /// + /// 创 建: + /// 日 期:2022/8/24 16:03:10 + /// 描 述:待办事项对多SysUser + /// + [Tenant("0")] + [SugarTable("schedule_sysuser_mapping11")] + public class Schedule_SysUser_Mapping + { + + [SugarColumn(IsPrimaryKey = true, ColumnName = "ScheduleId")] + public long ScheduleId { get; set; } + + + [SugarColumn(IsPrimaryKey = true, ColumnName = "SysUserId")] + public long SysUserId { get; set; } + } + /// + /// 创 建: + /// 日 期:2022/8/24 8:56:38 + /// 描 述:系统用户 + /// + [Tenant("0")] + [SugarTable("sys_user11")] + public class SysUserEntity + { + /// + /// 用户账号() + /// + [SugarColumn(ColumnDescription = "用户账号", ColumnName = "userName", IsNullable = false, Length = 30)] + public string userName { get; set; } + + + + /// + /// 用户 userId + /// + [SugarColumn(ColumnDescription = "用户ID", ColumnName = "userId", IsNullable = false, IsPrimaryKey = true )] + + public long Id { get; set; } + + + + + + + } +}