mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Add unit test
This commit is contained in:
parent
9f8c97685e
commit
a30291aa3a
@ -97,6 +97,7 @@
|
|||||||
<Compile Include="Models\OrderItem.cs" />
|
<Compile Include="Models\OrderItem.cs" />
|
||||||
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
|
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
|
||||||
<Compile Include="Models\ViewOrder.cs" />
|
<Compile Include="Models\ViewOrder.cs" />
|
||||||
|
<Compile Include="UnitTest\UnitManyToManyDeleteNav.cs" />
|
||||||
<Compile Include="UnitTest\UnitCustom12312.cs" />
|
<Compile Include="UnitTest\UnitCustom12312.cs" />
|
||||||
<Compile Include="UnitTest\UnitEnum22.cs" />
|
<Compile Include="UnitTest\UnitEnum22.cs" />
|
||||||
<Compile Include="UnitTest\UCustom025.cs" />
|
<Compile Include="UnitTest\UCustom025.cs" />
|
||||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
|||||||
}
|
}
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
|
UnitManyToManyDeleteNav.Init();
|
||||||
UnitTestReturnPkList.Init();
|
UnitTestReturnPkList.Init();
|
||||||
UnitCustom12312.Init();
|
UnitCustom12312.Init();
|
||||||
UnitEnum22.Init();
|
UnitEnum22.Init();
|
||||||
|
143
Src/Asp.Net/SqlServerTest/UnitTest/UnitManyToManyDeleteNav.cs
Normal file
143
Src/Asp.Net/SqlServerTest/UnitTest/UnitManyToManyDeleteNav.cs
Normal file
@ -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<ScheduleEntity>();
|
||||||
|
db.CodeFirst.InitTables<Schedule_SysUser_Mapping>();
|
||||||
|
db.CodeFirst.InitTables<SysUserEntity>();
|
||||||
|
}
|
||||||
|
//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<Schedule_SysUser_Mapping>(x => schIds.Contains(x.ScheduleId) && x.SysUserId == userId).ExecuteCommand();
|
||||||
|
//只删除关系
|
||||||
|
db.DeleteNav<ScheduleEntity>(x => x.BusinessKey == businessKey)
|
||||||
|
.Include(x => x.SysUsers.Where(u => u.Id == 100).ToList()) // B表
|
||||||
|
.ExecuteCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 创 建:
|
||||||
|
/// 日 期:2022/8/24 16:03:03
|
||||||
|
/// 描 述:待办事项
|
||||||
|
///</summary>
|
||||||
|
|
||||||
|
[SugarTable("sys_schedule11")]
|
||||||
|
public class ScheduleEntity
|
||||||
|
{
|
||||||
|
|
||||||
|
[SugarColumn(IsPrimaryKey = true, ColumnName = "id")]
|
||||||
|
public long Id { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 0:未读,1:进行中,2:完成
|
||||||
|
///</summary>
|
||||||
|
[SugarColumn(ColumnDescription = "状态", ColumnName = "status", IsNullable = true )]
|
||||||
|
public int? Status { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 摘要()
|
||||||
|
///</summary>
|
||||||
|
[SugarColumn(ColumnDescription = "摘要", ColumnName = "summary", IsNullable = true, Length = 255)]
|
||||||
|
public string Summary { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 内容()
|
||||||
|
///</summary>
|
||||||
|
[SugarColumn(ColumnDescription = "内容", ColumnName = "content", IsNullable = true, Length = 255)]
|
||||||
|
public string Content { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 路由()
|
||||||
|
///</summary>
|
||||||
|
[SugarColumn(ColumnDescription = "路由", ColumnName = "route", IsNullable = true, Length = 255)]
|
||||||
|
public string Route { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 路由参数()
|
||||||
|
///</summary>
|
||||||
|
[SugarColumn(ColumnDescription = "路由参数", ColumnDataType = "text", ColumnName = "routingParameters", IsNullable = true )]
|
||||||
|
public string RoutingParameters { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 业务Key()
|
||||||
|
///</summary>
|
||||||
|
[SugarColumn(ColumnDescription = "业务Key", ColumnName = "businessKey", IsNullable = true, Length = 255)]
|
||||||
|
public string BusinessKey { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 系统用户
|
||||||
|
///</summary>
|
||||||
|
[Navigate(typeof(Schedule_SysUser_Mapping), nameof(Schedule_SysUser_Mapping.ScheduleId), nameof(Schedule_SysUser_Mapping.SysUserId))]//注意顺序
|
||||||
|
public List<SysUserEntity> SysUsers { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 创 建:
|
||||||
|
/// 日 期:2022/8/24 16:03:10
|
||||||
|
/// 描 述:待办事项对多SysUser
|
||||||
|
///</summary>
|
||||||
|
[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; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 创 建:
|
||||||
|
/// 日 期:2022/8/24 8:56:38
|
||||||
|
/// 描 述:系统用户
|
||||||
|
///</summary>
|
||||||
|
[Tenant("0")]
|
||||||
|
[SugarTable("sys_user11")]
|
||||||
|
public class SysUserEntity
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 用户账号()
|
||||||
|
///</summary>
|
||||||
|
[SugarColumn(ColumnDescription = "用户账号", ColumnName = "userName", IsNullable = false, Length = 30)]
|
||||||
|
public string userName { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用户 userId
|
||||||
|
///</summary>
|
||||||
|
[SugarColumn(ColumnDescription = "用户ID", ColumnName = "userId", IsNullable = false, IsPrimaryKey = true )]
|
||||||
|
|
||||||
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user