mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 13:06:50 +08:00
Add unit test
This commit is contained in:
parent
810aed7e9e
commit
5b203e268c
@ -97,6 +97,7 @@
|
||||
<Compile Include="Models\OrderItem.cs" />
|
||||
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
|
||||
<Compile Include="Models\ViewOrder.cs" />
|
||||
<Compile Include="UnitTest\UnitUpdateNavN3.cs" />
|
||||
<Compile Include="UnitTest\UnitOneToOne12.cs" />
|
||||
<Compile Include="UnitTest\Models\poetry_video_comment.cs" />
|
||||
<Compile Include="UnitTest\Models\user_name_simple.cs" />
|
||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
UnitUpdateNavN3.Init();
|
||||
UnitOneToOne12.Init();
|
||||
UnitInsertNav3.Init();
|
||||
UnitInsertNav2.Init();
|
||||
|
95
Src/Asp.Net/SqlServerTest/UnitTest/UnitUpdateNavN3.cs
Normal file
95
Src/Asp.Net/SqlServerTest/UnitTest/UnitUpdateNavN3.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class UnitUpdateNavN3
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
var db = NewUnitTest.Db;
|
||||
|
||||
db.CodeFirst.InitTables(typeof(ClassA), typeof(ClassB), typeof(ClassC));
|
||||
db.DbMaintenance.TruncateTable<ClassA,ClassB,ClassC>();
|
||||
|
||||
|
||||
//初始化数据 1对多-1对多 共三层
|
||||
ClassA a = new ClassA();
|
||||
a.AId = "a";
|
||||
|
||||
ClassB b = new ClassB();
|
||||
b.BId = "b";
|
||||
b.AId = a.AId;
|
||||
a.B = new List<ClassB>();
|
||||
a.B.Add(b);
|
||||
|
||||
ClassC c = new ClassC();
|
||||
c.CId = "c";
|
||||
c.BId = b.BId;
|
||||
b.C = new List<ClassC>();
|
||||
b.C.Add(c);
|
||||
|
||||
//导航插入三表数据
|
||||
db.InsertNav(a).Include(t => t.B).ThenInclude(t => t.C).ExecuteCommand();
|
||||
|
||||
//修改数据 修改b表id 修改c表对应b表id
|
||||
b.BId = "bb";
|
||||
c.BId = "bb";
|
||||
c.CId = "cc";
|
||||
|
||||
|
||||
//导航更新三表数据
|
||||
db.UpdateNav(a).Include(t => t.B).ThenInclude(t => t.C).ExecuteCommand();
|
||||
|
||||
//正常情况C数据库中应该只有1条 如果是多条则说明三级表数据存在垃圾数据
|
||||
var count = db.Queryable<ClassC>().ToList();
|
||||
|
||||
|
||||
//清空表中数据
|
||||
db.DbMaintenance.DropTable("ClassA");
|
||||
db.DbMaintenance.DropTable("ClassB");
|
||||
db.DbMaintenance.DropTable("ClassC");
|
||||
Console.WriteLine($"第三级表中总数据条数:{count}");
|
||||
}
|
||||
/// <summary>
|
||||
/// 一级类
|
||||
/// </summary>
|
||||
[SugarTable("tb_a")]
|
||||
public class ClassA
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public string AId { get; set; }
|
||||
[Navigate(NavigateType.OneToMany, nameof(ClassB.AId))]
|
||||
public List<ClassB> B { get; set; }
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? UpdateTime { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 二级类
|
||||
/// </summary>
|
||||
[SugarTable("tb_b")]
|
||||
public class ClassB
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public string BId { get; set; }
|
||||
public string AId { get; set; }
|
||||
[Navigate(NavigateType.OneToMany, nameof(ClassC.BId))]
|
||||
public List<ClassC> C { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 三级类
|
||||
/// </summary>
|
||||
[SugarTable("tb_c")]
|
||||
public class ClassC
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public string CId { get; set; }
|
||||
|
||||
public string BId { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user