mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 05:13:27 +08:00
chore: 补充多个测试场景
This commit is contained in:
parent
1ec6453aad
commit
e1b88ab95c
@ -13,12 +13,37 @@ namespace MySqlTest.Demo
|
|||||||
{
|
{
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
Task.Run(Test_ToParentList).Wait();
|
Test_ToParentList();
|
||||||
|
Test_ToParentListWhere();
|
||||||
|
Task.Run(Test_ToParentListAsync).Wait();
|
||||||
|
Task.Run(Test_ToParentListWhereAsync).Wait();
|
||||||
}
|
}
|
||||||
private static async Task Test_ToParentList()
|
|
||||||
|
private static void Test_ToParentList()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
var data = db.Queryable<CustomerAddressTemplateDetail>().ToParentList(x => x.ParentCode, 2);
|
||||||
|
var data2 = db.Queryable<District>().ToParentList(x => x.ParentId, 110101004004);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Test_ToParentListWhere()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
var data = db.Queryable<CustomerAddressTemplateDetail>().ToParentList(x => x.ParentCode, 2, x => x.TemplateId == 1611933284013932544);
|
||||||
|
var data2 = db.Queryable<District>().ToParentList(x => x.ParentId, 110101004004,x=>x.DeletedAt==0);
|
||||||
|
}
|
||||||
|
private static async Task Test_ToParentListAsync()
|
||||||
|
{
|
||||||
|
var db = GetInstance();
|
||||||
|
var data = await db.Queryable<CustomerAddressTemplateDetail>().ToParentListAsync(x => x.ParentCode, 2);
|
||||||
|
var data2 = await db.Queryable<District>().ToParentListAsync(x => x.ParentId, 110101004004);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task Test_ToParentListWhereAsync()
|
||||||
{
|
{
|
||||||
var db = GetInstance();
|
var db = GetInstance();
|
||||||
var data = await db.Queryable<CustomerAddressTemplateDetail>().ToParentListAsync(x => x.ParentCode, 2, x => x.TemplateId == 1611933284013932544);
|
var data = await db.Queryable<CustomerAddressTemplateDetail>().ToParentListAsync(x => x.ParentCode, 2, x => x.TemplateId == 1611933284013932544);
|
||||||
|
var data2 = await db.Queryable<District>().ToParentListAsync(x => x.ParentId, 110101004004, x => x.DeletedAt == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SqlSugarClient GetInstance()
|
private static SqlSugarClient GetInstance()
|
||||||
@ -26,7 +51,7 @@ namespace MySqlTest.Demo
|
|||||||
return new SqlSugarClient(new ConnectionConfig()
|
return new SqlSugarClient(new ConnectionConfig()
|
||||||
{
|
{
|
||||||
DbType = SqlSugar.DbType.MySql,
|
DbType = SqlSugar.DbType.MySql,
|
||||||
ConnectionString = Config.ConnectionString,
|
ConnectionString = "Data Source=192.168.95.11;port=33306;Database=cube;AllowLoadLocalInfile=true;User ID=root;Password=dljs2022;allowPublicKeyRetrieval=true;pooling=true;CharSet=utf8;sslmode=none;AllowUserVariables=true;",
|
||||||
InitKeyType = InitKeyType.Attribute,
|
InitKeyType = InitKeyType.Attribute,
|
||||||
IsAutoCloseConnection = true,
|
IsAutoCloseConnection = true,
|
||||||
AopEvents = new AopEvents
|
AopEvents = new AopEvents
|
||||||
@ -70,6 +95,24 @@ namespace MySqlTest.Demo
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
[SugarTable("district", TableDescription = "省市区街道村5级信息(https://github.com/adyliu/china_area)")]
|
||||||
|
[SugarIndex("idx_parentid_level", nameof(ParentId), OrderByType.Asc, nameof(Level), OrderByType.Asc)]
|
||||||
|
public class District
|
||||||
|
{
|
||||||
|
[SugarColumn(IsPrimaryKey = true)]
|
||||||
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
[SugarColumn(ColumnDescription = "上级Id")]
|
||||||
|
public long ParentId { get; set; }
|
||||||
|
|
||||||
|
[SugarColumn(ColumnDescription = "名称", Length = 128)]
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[SugarColumn(ColumnDescription = "级别")]
|
||||||
|
public int Level { get; set; }
|
||||||
|
|
||||||
|
public long DeletedAt { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user