2022-08-01 16:38:23 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
|
|
namespace OrmTest
|
|
|
|
|
{
|
|
|
|
|
public static class UnitOneToOneN2
|
|
|
|
|
{
|
|
|
|
|
public static void Init()
|
|
|
|
|
{
|
|
|
|
|
var db = NewUnitTest.Db;
|
|
|
|
|
|
|
|
|
|
////建表
|
2023-01-12 19:35:28 +08:00
|
|
|
|
|
2022-08-01 16:38:23 +08:00
|
|
|
|
//db.DbMaintenance.TruncateTable<Country, Province, City>();
|
|
|
|
|
|
|
|
|
|
//用例代码
|
|
|
|
|
var result = db.Queryable<Country>()
|
|
|
|
|
.Where(Country => Country.Province.City.CityId == 1)
|
|
|
|
|
.ToSqlString();//用例代码
|
|
|
|
|
|
2023-01-12 19:35:28 +08:00
|
|
|
|
if (!result.Contains("[City1].[ProvinceId]=[Province0].[ProvinceId]"))
|
2022-08-01 16:38:23 +08:00
|
|
|
|
{
|
|
|
|
|
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; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|