mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Add unit test
This commit is contained in:
parent
db5f8a9c13
commit
51a682070a
@ -97,6 +97,7 @@
|
||||
<Compile Include="Models\OrderItem.cs" />
|
||||
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
|
||||
<Compile Include="Models\ViewOrder.cs" />
|
||||
<Compile Include="UnitTest\UnitOneToOneN2.cs" />
|
||||
<Compile Include="UnitTest\UnitManyToManyUpdate.cs" />
|
||||
<Compile Include="UnitTest\UnitManyToMay1231.cs" />
|
||||
<Compile Include="UnitTest\UnitOneToOneN.cs" />
|
||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
UnitOneToOneN2.Init();
|
||||
UnitManyToManyUpdate.Init();
|
||||
UnitManyToMay1231.Init();
|
||||
UnitUpdateNav2.Init();
|
||||
|
56
Src/Asp.Net/SqlServerTest/UnitTest/UnitOneToOneN2.cs
Normal file
56
Src/Asp.Net/SqlServerTest/UnitTest/UnitOneToOneN2.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
|
||||
using SqlSugar;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public static class UnitOneToOneN2
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
var db = NewUnitTest.Db;
|
||||
|
||||
////建表
|
||||
//db.CodeFirst.InitTables<Country, Province, City>();
|
||||
//db.DbMaintenance.TruncateTable<Country, Province, City>();
|
||||
|
||||
//用例代码
|
||||
var result = db.Queryable<Country>()
|
||||
.Where(Country => Country.Province.City.CityId == 1)
|
||||
.ToSqlString();//用例代码
|
||||
|
||||
if (!result.Contains("City1.[ProvinceId]=Province0.[ProvinceId]"))
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//建类
|
||||
public class Country
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public int CountryId { get; set; }
|
||||
public int ProvinceId { get; set; }
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
[Navigate(NavigateType.OneToOne, nameof(ProvinceId))]
|
||||
public Province Province { get; set; }
|
||||
}
|
||||
|
||||
public class Province
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public int ProvinceId { get; set; }
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
[Navigate(NavigateType.OneToOne, nameof(ProvinceId), nameof(UnitOneToOneN2.City.ProvinceId))]
|
||||
public City City { get; set; }
|
||||
}
|
||||
|
||||
public class City
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public int CityId { get; set; }
|
||||
public int ProvinceId { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user