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
6675e17698
commit
96ac3b63af
@ -33,6 +33,9 @@ namespace OrmTest
|
||||
{
|
||||
|
||||
UOneManyMany.init();
|
||||
UOneManyMany2.init();
|
||||
UOneManyMany3.init();
|
||||
UOneManyMany4.init();
|
||||
UNavDynamic111N.Init();
|
||||
UCustom019.Init();
|
||||
UCustom015.Init();
|
||||
|
@ -9,36 +9,36 @@ namespace OrmTest
|
||||
public class UOneManyMany
|
||||
{
|
||||
|
||||
public static void init()
|
||||
public static void init()
|
||||
{
|
||||
|
||||
var db = NewUnitTest.Db;
|
||||
db.CodeFirst.InitTables<Student_001, School_001, Room_001,Desk_001>();
|
||||
db.CodeFirst.InitTables<Student_001, School_001, Room_001, Desk_001>();
|
||||
db.DbMaintenance.TruncateTable<Student_001, School_001, Room_001, Desk_001>();
|
||||
|
||||
db.Insertable(new Student_001() { sid = 1, Name = "北大jack", SchoolId = 1 }).ExecuteCommand();
|
||||
db.Insertable(new Student_001() { sid = 2, Name = "青华jack", SchoolId = 2}).ExecuteCommand();
|
||||
db.Insertable(new Student_001() { sid = 2, Name = "青华jack", SchoolId = 2 }).ExecuteCommand();
|
||||
|
||||
db.Insertable(new School_001() { scid = 1, schname = "北大" }).ExecuteCommand();
|
||||
db.Insertable(new School_001() { scid = 2, schname = "青华" }).ExecuteCommand();
|
||||
db.Insertable(new School_001() { scid = 1, schname = "北大" }).ExecuteCommand();
|
||||
db.Insertable(new School_001() { scid = 2, schname = "青华" }).ExecuteCommand();
|
||||
|
||||
|
||||
db.Insertable(new Room_001() { roomId = 1, schoolId =1, roomName= "北大01室" }).ExecuteCommand();
|
||||
db.Insertable(new Room_001() { roomId = 2, schoolId =1, roomName="北大02室" }).ExecuteCommand();
|
||||
db.Insertable(new Room_001() { roomId = 1, schoolId = 1, roomName = "北大01室" }).ExecuteCommand();
|
||||
db.Insertable(new Room_001() { roomId = 2, schoolId = 1, roomName = "北大02室" }).ExecuteCommand();
|
||||
db.Insertable(new Room_001() { roomId = 3, schoolId = 2, roomName = "青华03室" }).ExecuteCommand();
|
||||
db.Insertable(new Room_001() { roomId = 4, schoolId = 2, roomName = "青华04室" }).ExecuteCommand();
|
||||
|
||||
db.Insertable(new Desk_001() { roomId = 1, deskid = 1, deskName = "北大01室_01" }).ExecuteCommand();
|
||||
db.Insertable(new Desk_001() { roomId = 2, deskid = 2, deskName = "北大02室_01" }).ExecuteCommand();
|
||||
db.Insertable(new Desk_001() { roomId = 3, deskid = 3, deskName = "青华03室_01" }).ExecuteCommand();
|
||||
db.Insertable(new Desk_001() { roomId = 1, deskid = 1, deskName = "北大01室_01" }).ExecuteCommand();
|
||||
db.Insertable(new Desk_001() { roomId = 2, deskid = 2, deskName = "北大02室_01" }).ExecuteCommand();
|
||||
db.Insertable(new Desk_001() { roomId = 3, deskid = 3, deskName = "青华03室_01" }).ExecuteCommand();
|
||||
db.Insertable(new Desk_001() { roomId = 4, deskid = 4, deskName = "青华04室_01" }).ExecuteCommand();
|
||||
|
||||
|
||||
var list=db.Queryable<Student_001>()
|
||||
.Includes(x => x.school_001, x => x.rooms)
|
||||
.Where(x=>x.school_001.rooms.Any(z=>z.rooms.Any())).ToList();
|
||||
var list = db.Queryable<Student_001>()
|
||||
.Includes(x => x.school_001, x => x.rooms, x => x.desk)
|
||||
.Where(x => x.school_001.rooms.Any(z => z.desk.Any())).ToList();
|
||||
|
||||
if (list.Count() !=2)
|
||||
if (list.Count() != 2)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
@ -46,8 +46,8 @@ namespace OrmTest
|
||||
var list2 = db.Queryable<Student_001>()
|
||||
.Includes(x => x.school_001, x => x.rooms)
|
||||
.Where(x => x.school_001.rooms.Any(z =>
|
||||
z.roomName== "北大01室" &&
|
||||
z.rooms.Any())).ToList();
|
||||
z.roomName == "北大01室" &&
|
||||
z.desk.Any())).ToList();
|
||||
|
||||
|
||||
if (list2.Count() != 1)
|
||||
@ -56,12 +56,12 @@ namespace OrmTest
|
||||
}
|
||||
|
||||
var list3 = db.Queryable<Student_001>()
|
||||
.Includes(x=>x.school_001,x=>x.rooms)
|
||||
.Includes(x => x.school_001, x => x.rooms)
|
||||
.Where(x => x.school_001.rooms.Any(z =>
|
||||
z.roomName == "青华03室" &&
|
||||
z.rooms.Any(c=>c.deskName== "青华03室_01"))).ToList();
|
||||
z.desk.Any(c => c.deskName == "青华03室_01"))).ToList();
|
||||
|
||||
if (list3.Count != 1)
|
||||
if (list3.Count != 1)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
@ -69,14 +69,28 @@ namespace OrmTest
|
||||
var list4 = db.Queryable<Student_001>()
|
||||
.Where(x => x.school_001.rooms.Any(z =>
|
||||
z.roomName == "青华03室" &&
|
||||
z.rooms.Any(c => c.deskName == "青华04室_01"))).ToList();
|
||||
z.desk.Any(c => c.deskName == "青华04室_01"))).ToList();
|
||||
|
||||
|
||||
if (list4.Count != 0)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
db.DbMaintenance.TruncateTable<Student_001, School_001, Room_001, Desk_001>();
|
||||
db.InsertNav(list.First())
|
||||
.ThenInclude(x => x.school_001)
|
||||
.ThenInclude(x => x.rooms)
|
||||
.ThenInclude(x => x.desk).ExecuteCommand();
|
||||
db.InsertNav(list.Last())
|
||||
.ThenInclude(x => x.school_001)
|
||||
.ThenInclude(x => x.rooms)
|
||||
.ThenInclude(x => x.desk).ExecuteCommand();
|
||||
|
||||
if (db.Queryable<Desk_001>().Count() != 4 || db.Queryable<Room_001>().Count() != 4
|
||||
|| db.Queryable<School_001>().Count() != 2 || db.Queryable<Student_001>().Count() != 2)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
}
|
||||
|
||||
public class Student_001
|
||||
@ -107,7 +121,7 @@ namespace OrmTest
|
||||
public int schoolId { get; set; }
|
||||
public string roomName { get; set; }
|
||||
[SqlSugar.Navigate(SqlSugar.NavigateType.OneToMany, nameof(Desk_001.roomId))]
|
||||
public List<Desk_001> rooms { get; set; }
|
||||
public List<Desk_001> desk { get; set; }
|
||||
}
|
||||
|
||||
public class Desk_001
|
||||
|
166
Src/Asp.NetCore2/SqlSeverTest/UnitTest/UOneManyMany2.cs
Normal file
166
Src/Asp.NetCore2/SqlSeverTest/UnitTest/UOneManyMany2.cs
Normal file
@ -0,0 +1,166 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class UOneManyMany2
|
||||
{
|
||||
|
||||
public static void init()
|
||||
{
|
||||
|
||||
var db = NewUnitTest.Db;
|
||||
db.CodeFirst.InitTables<Student_002, School_002, Room_002, Desk_002>();
|
||||
db.DbMaintenance.TruncateTable<Student_002, School_002, Room_002, Desk_002>();
|
||||
|
||||
db.Insertable(new Student_002() { sid = 1, Name = "北大jack", SchoolId = 1 }).ExecuteCommand();
|
||||
db.Insertable(new Student_002() { sid = 2, Name = "青华jack", SchoolId = 2 }).ExecuteCommand();
|
||||
|
||||
db.Insertable(new School_002() { scid = 1, schname = "北大" }).ExecuteCommand();
|
||||
db.Insertable(new School_002() { scid = 2, schname = "青华" }).ExecuteCommand();
|
||||
|
||||
|
||||
db.Insertable(new Room_002() { roomId = 1, schoolId = 1, roomName = "北大01室" }).ExecuteCommand();
|
||||
db.Insertable(new Room_002() { roomId = 2, schoolId = 1, roomName = "北大02室" }).ExecuteCommand();
|
||||
db.Insertable(new Room_002() { roomId = 3, schoolId = 2, roomName = "青华03室" }).ExecuteCommand();
|
||||
db.Insertable(new Room_002() { roomId = 4, schoolId = 2, roomName = "青华04室" }).ExecuteCommand();
|
||||
|
||||
db.Insertable(new Desk_002() { roomId = 1, deskid = 1, deskName = "北大01室_01" }).ExecuteCommand();
|
||||
db.Insertable(new Desk_002() { roomId = 2, deskid = 2, deskName = "北大02室_01" }).ExecuteCommand();
|
||||
db.Insertable(new Desk_002() { roomId = 3, deskid = 3, deskName = "青华03室_01" }).ExecuteCommand();
|
||||
db.Insertable(new Desk_002() { roomId = 4, deskid = 4, deskName = "青华04室_01" }).ExecuteCommand();
|
||||
|
||||
|
||||
var list = db.Queryable<Student_002>()
|
||||
.Includes(x => x.school_001, x => x.rooms, x => x.desk)
|
||||
.Where(x => x.school_001.rooms.Any(z => z.desk.Any())).ToList();
|
||||
|
||||
if (list.Count() != 2)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
|
||||
var list2 = db.Queryable<Student_002>()
|
||||
.Includes(x => x.school_001, x => x.rooms)
|
||||
.Where(x => x.school_001.rooms.Any(z =>
|
||||
z.roomName == "北大01室" &&
|
||||
z.desk.Any())).ToList();
|
||||
|
||||
|
||||
if (list2.Count() != 1)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
|
||||
var list3 = db.Queryable<Student_002>()
|
||||
.Includes(x => x.school_001, x => x.rooms)
|
||||
.Where(x => x.school_001.rooms.Any(z =>
|
||||
z.roomName == "青华03室" &&
|
||||
z.desk.Any(c => c.deskName == "青华03室_01"))).ToList();
|
||||
|
||||
if (list3.Count != 1)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
|
||||
var list4 = db.Queryable<Student_002>()
|
||||
.Where(x => x.school_001.rooms.Any(z =>
|
||||
z.roomName == "青华03室" &&
|
||||
z.desk.Any(c => c.deskName == "青华04室_01"))).ToList();
|
||||
|
||||
|
||||
if (list4.Count != 0)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
db.DbMaintenance.TruncateTable<Student_002, School_002, Room_002, Desk_002>();
|
||||
foreach (var item in list)
|
||||
{
|
||||
item.sid = 0;
|
||||
item.SchoolId = 0;
|
||||
item.school_001.scid = 0;
|
||||
foreach (var r in item.school_001.rooms)
|
||||
{
|
||||
r.roomId = 0;
|
||||
r.schoolId = 0;
|
||||
foreach (var z in r.desk)
|
||||
{
|
||||
z.deskid = 0;
|
||||
z.roomId = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
db.InsertNav(list.First())
|
||||
.ThenInclude(x => x.school_001)
|
||||
.ThenInclude(x => x.rooms)
|
||||
.ThenInclude(x => x.desk).ExecuteCommand();
|
||||
db.InsertNav(list.Last())
|
||||
.ThenInclude(x => x.school_001)
|
||||
.ThenInclude(x => x.rooms)
|
||||
.ThenInclude(x => x.desk).ExecuteCommand();
|
||||
|
||||
if (db.Queryable<Desk_002>().Count() != 4 || db.Queryable<Room_002>().Count() != 4
|
||||
|| db.Queryable<School_002>().Count() != 2 || db.Queryable<Student_002>().Count() != 2)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
|
||||
db.DbMaintenance.TruncateTable<Student_002, School_002, Room_002, Desk_002>();
|
||||
|
||||
db.InsertNav(list.First().school_001)
|
||||
.ThenInclude(x => x.rooms)
|
||||
.ThenInclude(x => x.desk).ExecuteCommand();
|
||||
db.InsertNav(list.Last().school_001)
|
||||
.ThenInclude(x => x.rooms)
|
||||
.ThenInclude(x => x.desk).ExecuteCommand();
|
||||
|
||||
if (db.Queryable<Desk_002>().Count() != 4 || db.Queryable<Room_002>().Count() != 4
|
||||
|| db.Queryable<School_002>().Count() != 2 || db.Queryable<Student_002>().Count() != 0)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
}
|
||||
|
||||
public class Student_002
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey =true,IsIdentity =true)]
|
||||
public int sid { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public int SchoolId { get; set; }
|
||||
[SqlSugar.Navigate(SqlSugar.NavigateType.OneToOne,nameof(SchoolId))]
|
||||
public School_002 school_001 { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class School_002
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int scid { get; set; }
|
||||
public string schname { get; set; }
|
||||
[SqlSugar.Navigate(SqlSugar.NavigateType.OneToMany, nameof(Room_002.schoolId))]
|
||||
public List<Room_002> rooms { get; set; }
|
||||
}
|
||||
|
||||
public class Room_002
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int roomId { get; set; }
|
||||
public int schoolId { get; set; }
|
||||
public string roomName { get; set; }
|
||||
[SqlSugar.Navigate(SqlSugar.NavigateType.OneToMany, nameof(Desk_002.roomId))]
|
||||
public List<Desk_002> desk { get; set; }
|
||||
}
|
||||
|
||||
public class Desk_002
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int deskid { get; set; }
|
||||
public string deskName { get; set; }
|
||||
public int roomId { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
166
Src/Asp.NetCore2/SqlSeverTest/UnitTest/UOneManyMany3.cs
Normal file
166
Src/Asp.NetCore2/SqlSeverTest/UnitTest/UOneManyMany3.cs
Normal file
@ -0,0 +1,166 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class UOneManyMany3
|
||||
{
|
||||
|
||||
public static void init()
|
||||
{
|
||||
|
||||
var db = NewUnitTest.Db;
|
||||
db.CodeFirst.InitTables<Student_003, School_003, Room_003, Desk_003>();
|
||||
db.DbMaintenance.TruncateTable<Student_003, School_003, Room_003, Desk_003>();
|
||||
|
||||
db.Insertable(new Student_003() { sid = 1, Name = "北大jack", SchoolId = 1 }).ExecuteCommand();
|
||||
db.Insertable(new Student_003() { sid = 2, Name = "青华jack", SchoolId = 2 }).ExecuteCommand();
|
||||
|
||||
db.Insertable(new School_003() { scid = 1, schname = "北大" }).ExecuteCommand();
|
||||
db.Insertable(new School_003() { scid = 2, schname = "青华" }).ExecuteCommand();
|
||||
|
||||
|
||||
db.Insertable(new Room_003() { roomId = 1, schoolId = 1, roomName = "北大01室" }).ExecuteCommand();
|
||||
db.Insertable(new Room_003() { roomId = 2, schoolId = 1, roomName = "北大02室" }).ExecuteCommand();
|
||||
db.Insertable(new Room_003() { roomId = 3, schoolId = 2, roomName = "青华03室" }).ExecuteCommand();
|
||||
db.Insertable(new Room_003() { roomId = 4, schoolId = 2, roomName = "青华04室" }).ExecuteCommand();
|
||||
|
||||
db.Insertable(new Desk_003() { roomId = 1, deskid = 1, deskName = "北大01室_01" }).ExecuteCommand();
|
||||
db.Insertable(new Desk_003() { roomId = 2, deskid = 2, deskName = "北大02室_01" }).ExecuteCommand();
|
||||
db.Insertable(new Desk_003() { roomId = 3, deskid = 3, deskName = "青华03室_01" }).ExecuteCommand();
|
||||
db.Insertable(new Desk_003() { roomId = 4, deskid = 4, deskName = "青华04室_01" }).ExecuteCommand();
|
||||
|
||||
|
||||
var list = db.Queryable<Student_003>()
|
||||
.Includes(x => x.school_001, x => x.rooms, x => x.desk)
|
||||
.Where(x => x.school_001.rooms.Any(z => z.desk.Any())).ToList();
|
||||
|
||||
if (list.Count() != 2)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
|
||||
var list2 = db.Queryable<Student_003>()
|
||||
.Includes(x => x.school_001, x => x.rooms)
|
||||
.Where(x => x.school_001.rooms.Any(z =>
|
||||
z.roomName == "北大01室" &&
|
||||
z.desk.Any())).ToList();
|
||||
|
||||
|
||||
if (list2.Count() != 1)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
|
||||
var list3 = db.Queryable<Student_003>()
|
||||
.Includes(x => x.school_001, x => x.rooms)
|
||||
.Where(x => x.school_001.rooms.Any(z =>
|
||||
z.roomName == "青华03室" &&
|
||||
z.desk.Any(c => c.deskName == "青华03室_01"))).ToList();
|
||||
|
||||
if (list3.Count != 1)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
|
||||
var list4 = db.Queryable<Student_003>()
|
||||
.Where(x => x.school_001.rooms.Any(z =>
|
||||
z.roomName == "青华03室" &&
|
||||
z.desk.Any(c => c.deskName == "青华04室_01"))).ToList();
|
||||
|
||||
|
||||
if (list4.Count != 0)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
db.DbMaintenance.TruncateTable<Student_003, School_003, Room_003, Desk_003>();
|
||||
foreach (var item in list)
|
||||
{
|
||||
item.sid = 0;
|
||||
item.SchoolId = 0;
|
||||
item.school_001.scid = 0;
|
||||
foreach (var r in item.school_001.rooms)
|
||||
{
|
||||
r.roomId = 0;
|
||||
r.schoolId = 0;
|
||||
foreach (var z in r.desk)
|
||||
{
|
||||
z.deskid = 0;
|
||||
z.roomId = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
db.InsertNav(list.First())
|
||||
.ThenInclude(x => x.school_001)
|
||||
.ThenInclude(x => x.rooms)
|
||||
.ThenInclude(x => x.desk).ExecuteCommand();
|
||||
db.InsertNav(list.Last())
|
||||
.ThenInclude(x => x.school_001)
|
||||
.ThenInclude(x => x.rooms)
|
||||
.ThenInclude(x => x.desk).ExecuteCommand();
|
||||
|
||||
if (db.Queryable<Desk_003>().Count() != 4 || db.Queryable<Room_003>().Count() != 4
|
||||
|| db.Queryable<School_003>().Count() != 2 || db.Queryable<Student_003>().Count() != 2)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
|
||||
db.DbMaintenance.TruncateTable<Student_003, School_003, Room_003, Desk_003>();
|
||||
|
||||
db.InsertNav(list.First().school_001)
|
||||
.ThenInclude(x => x.rooms)
|
||||
.ThenInclude(x => x.desk).ExecuteCommand();
|
||||
db.InsertNav(list.Last().school_001)
|
||||
.ThenInclude(x => x.rooms)
|
||||
.ThenInclude(x => x.desk).ExecuteCommand();
|
||||
|
||||
if (db.Queryable<Desk_003>().Count() != 4 || db.Queryable<Room_003>().Count() != 4
|
||||
|| db.Queryable<School_003>().Count() != 2 || db.Queryable<Student_003>().Count() != 0)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
}
|
||||
|
||||
public class Student_003
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey =true)]
|
||||
public long sid { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public long SchoolId { get; set; }
|
||||
[SqlSugar.Navigate(SqlSugar.NavigateType.OneToOne,nameof(SchoolId))]
|
||||
public School_003 school_001 { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class School_003
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true )]
|
||||
public long scid { get; set; }
|
||||
public string schname { get; set; }
|
||||
[SqlSugar.Navigate(SqlSugar.NavigateType.OneToMany, nameof(Room_003.schoolId))]
|
||||
public List<Room_003> rooms { get; set; }
|
||||
}
|
||||
|
||||
public class Room_003
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true )]
|
||||
public long roomId { get; set; }
|
||||
public long schoolId { get; set; }
|
||||
public string roomName { get; set; }
|
||||
[SqlSugar.Navigate(SqlSugar.NavigateType.OneToMany, nameof(Desk_003.roomId))]
|
||||
public List<Desk_003> desk { get; set; }
|
||||
}
|
||||
|
||||
public class Desk_003
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
|
||||
public long deskid { get; set; }
|
||||
public string deskName { get; set; }
|
||||
public long roomId { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
170
Src/Asp.NetCore2/SqlSeverTest/UnitTest/UOneManyMany4.cs
Normal file
170
Src/Asp.NetCore2/SqlSeverTest/UnitTest/UOneManyMany4.cs
Normal file
@ -0,0 +1,170 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class UOneManyMany4
|
||||
{
|
||||
|
||||
public static void init()
|
||||
{
|
||||
|
||||
var db = NewUnitTest.Db;
|
||||
db.CodeFirst.InitTables<Student_004, School_004, Room_004, Desk_004>();
|
||||
db.DbMaintenance.TruncateTable<Student_004, School_004, Room_004, Desk_004>();
|
||||
|
||||
var id1 = Guid.NewGuid();
|
||||
var id2 = Guid.NewGuid();
|
||||
var id3 = Guid.NewGuid();
|
||||
var id4 = Guid.NewGuid();
|
||||
db.Insertable(new Student_004() { sid = id1, Name = "北大jack", SchoolId = id1 }).ExecuteCommand();
|
||||
db.Insertable(new Student_004() { sid = id2, Name = "青华jack", SchoolId = id2 }).ExecuteCommand();
|
||||
|
||||
db.Insertable(new School_004() { scid = id1, schname = "北大" }).ExecuteCommand();
|
||||
db.Insertable(new School_004() { scid = id2, schname = "青华" }).ExecuteCommand();
|
||||
|
||||
|
||||
db.Insertable(new Room_004() { roomId = id1, schoolId = id1, roomName = "北大01室" }).ExecuteCommand();
|
||||
db.Insertable(new Room_004() { roomId = id2, schoolId = id1, roomName = "北大02室" }).ExecuteCommand();
|
||||
db.Insertable(new Room_004() { roomId = id3, schoolId = id2, roomName = "青华03室" }).ExecuteCommand();
|
||||
db.Insertable(new Room_004() { roomId = id4, schoolId = id2, roomName = "青华04室" }).ExecuteCommand();
|
||||
|
||||
db.Insertable(new Desk_004() { roomId = id1, deskid = id1, deskName = "北大01室_01" }).ExecuteCommand();
|
||||
db.Insertable(new Desk_004() { roomId = id2, deskid = id2, deskName = "北大02室_01" }).ExecuteCommand();
|
||||
db.Insertable(new Desk_004() { roomId = id3, deskid = id3, deskName = "青华03室_01" }).ExecuteCommand();
|
||||
db.Insertable(new Desk_004() { roomId = id4, deskid = id4, deskName = "青华04室_01" }).ExecuteCommand();
|
||||
|
||||
|
||||
var list = db.Queryable<Student_004>()
|
||||
.Includes(x => x.school_001, x => x.rooms, x => x.desk)
|
||||
.Where(x => x.school_001.rooms.Any(z => z.desk.Any())).ToList();
|
||||
|
||||
if (list.Count() != 2)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
|
||||
var list2 = db.Queryable<Student_004>()
|
||||
.Includes(x => x.school_001, x => x.rooms)
|
||||
.Where(x => x.school_001.rooms.Any(z =>
|
||||
z.roomName == "北大01室" &&
|
||||
z.desk.Any())).ToList();
|
||||
|
||||
|
||||
if (list2.Count() != 1)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
|
||||
var list3 = db.Queryable<Student_004>()
|
||||
.Includes(x => x.school_001, x => x.rooms)
|
||||
.Where(x => x.school_001.rooms.Any(z =>
|
||||
z.roomName == "青华03室" &&
|
||||
z.desk.Any(c => c.deskName == "青华03室_01"))).ToList();
|
||||
|
||||
if (list3.Count != 1)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
|
||||
var list4 = db.Queryable<Student_004>()
|
||||
.Where(x => x.school_001.rooms.Any(z =>
|
||||
z.roomName == "青华03室" &&
|
||||
z.desk.Any(c => c.deskName == "青华04室_01"))).ToList();
|
||||
|
||||
|
||||
if (list4.Count != 0)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
db.DbMaintenance.TruncateTable<Student_004, School_004, Room_004, Desk_004>();
|
||||
foreach (var item in list)
|
||||
{
|
||||
item.sid = Guid.Empty;
|
||||
item.SchoolId = Guid.Empty;
|
||||
item.school_001.scid = Guid.Empty;
|
||||
foreach (var r in item.school_001.rooms)
|
||||
{
|
||||
r.roomId = Guid.Empty;
|
||||
r.schoolId = Guid.Empty;
|
||||
foreach (var z in r.desk)
|
||||
{
|
||||
z.deskid = Guid.Empty;
|
||||
z.roomId = Guid.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
db.InsertNav(list.First())
|
||||
.ThenInclude(x => x.school_001)
|
||||
.ThenInclude(x => x.rooms)
|
||||
.ThenInclude(x => x.desk).ExecuteCommand();
|
||||
db.InsertNav(list.Last())
|
||||
.ThenInclude(x => x.school_001)
|
||||
.ThenInclude(x => x.rooms)
|
||||
.ThenInclude(x => x.desk).ExecuteCommand();
|
||||
|
||||
if (db.Queryable<Desk_004>().Count() != 4 || db.Queryable<Room_004>().Count() != 4
|
||||
|| db.Queryable<School_004>().Count() != 2 || db.Queryable<Student_004>().Count() != 2)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
|
||||
db.DbMaintenance.TruncateTable<Student_004, School_004, Room_004, Desk_004>();
|
||||
|
||||
db.InsertNav(list.First().school_001)
|
||||
.ThenInclude(x => x.rooms)
|
||||
.ThenInclude(x => x.desk).ExecuteCommand();
|
||||
db.InsertNav(list.Last().school_001)
|
||||
.ThenInclude(x => x.rooms)
|
||||
.ThenInclude(x => x.desk).ExecuteCommand();
|
||||
if (db.Queryable<Desk_004>().Count() != 4 || db.Queryable<Room_004>().Count() != 4
|
||||
|| db.Queryable<School_004>().Count() != 2 || db.Queryable<Student_004>().Count() != 0)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
}
|
||||
|
||||
public class Student_004
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey =true)]
|
||||
public Guid sid { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public Guid SchoolId { get; set; }
|
||||
[SqlSugar.Navigate(SqlSugar.NavigateType.OneToOne,nameof(SchoolId))]
|
||||
public School_004 school_001 { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class School_004
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true )]
|
||||
public Guid scid { get; set; }
|
||||
public string schname { get; set; }
|
||||
[SqlSugar.Navigate(SqlSugar.NavigateType.OneToMany, nameof(Room_004.schoolId))]
|
||||
public List<Room_004> rooms { get; set; }
|
||||
}
|
||||
|
||||
public class Room_004
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true )]
|
||||
public Guid roomId { get; set; }
|
||||
public Guid schoolId { get; set; }
|
||||
public string roomName { get; set; }
|
||||
[SqlSugar.Navigate(SqlSugar.NavigateType.OneToMany, nameof(Desk_004.roomId))]
|
||||
public List<Desk_004> desk { get; set; }
|
||||
}
|
||||
|
||||
public class Desk_004
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
|
||||
public Guid deskid { get; set; }
|
||||
public string deskName { get; set; }
|
||||
public Guid roomId { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user