mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Add unit test
This commit is contained in:
parent
e072e80ab9
commit
ba684e7f4b
@ -97,6 +97,7 @@
|
||||
<Compile Include="Models\OrderItem.cs" />
|
||||
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
|
||||
<Compile Include="Models\ViewOrder.cs" />
|
||||
<Compile Include="UnitTest\UnitOneToOneN.cs" />
|
||||
<Compile Include="UnitTest\UCustom024.cs" />
|
||||
<Compile Include="UnitTest\UCustomNavigate01.cs" />
|
||||
<Compile Include="UnitTest\Models\DSPersonScheduleModel.cs" />
|
||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
UnitOneToOneN.Init();
|
||||
ULock.Init();
|
||||
UnitManyToMany2.Init();
|
||||
UOneManyMany5.init();
|
||||
|
104
Src/Asp.Net/SqlServerTest/UnitTest/UnitOneToOneN.cs
Normal file
104
Src/Asp.Net/SqlServerTest/UnitTest/UnitOneToOneN.cs
Normal file
@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
namespace OrmTest
|
||||
{
|
||||
public class UnitOneToOneN
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
var db = NewUnitTest.Db;
|
||||
|
||||
|
||||
//建表
|
||||
|
||||
if (!db.DbMaintenance.IsAnyTable("StudentA", false))
|
||||
|
||||
{
|
||||
|
||||
db.CodeFirst.InitTables<StudentA>();
|
||||
|
||||
}
|
||||
|
||||
if (!db.DbMaintenance.IsAnyTable("SchoolA", false))
|
||||
|
||||
{
|
||||
|
||||
db.CodeFirst.InitTables<SchoolA>();
|
||||
|
||||
}
|
||||
|
||||
if (!db.DbMaintenance.IsAnyTable("RoomA", false))
|
||||
|
||||
{
|
||||
|
||||
db.CodeFirst.InitTables<RoomA>();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//用例代码
|
||||
|
||||
var result = db.Queryable<StudentA>()
|
||||
|
||||
.Select(student => student.School.Room.RoomId)
|
||||
|
||||
.ToSqlString();//用例代码
|
||||
|
||||
if (!result.Contains("student.[SchoolNo] = SchoolA0.[SchoolNo]"))
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
}
|
||||
|
||||
public class StudentA
|
||||
|
||||
{
|
||||
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
|
||||
public int StudentId { get; set; }
|
||||
|
||||
public int SchoolNo { get; set; }
|
||||
|
||||
[Navigate(NavigateType.OneToOne, nameof(SchoolNo), nameof(SchoolA.SchoolNo))]
|
||||
|
||||
public SchoolA School { get; set; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class SchoolA
|
||||
|
||||
{
|
||||
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
|
||||
public int SchoolId { get; set; }
|
||||
|
||||
public int SchoolNo { get; set; }
|
||||
|
||||
public int RoomId { get; set; }
|
||||
|
||||
[Navigate(NavigateType.OneToOne, nameof(RoomId))]
|
||||
|
||||
public RoomA Room { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class RoomA
|
||||
|
||||
{
|
||||
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
|
||||
public int RoomId { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user