mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 修复 ToTreeList 的问题 #255
This commit is contained in:
parent
f9c1003e81
commit
dc625218d6
@ -211,15 +211,6 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||
<summary>
|
||||
批量注入 Repository,可以参考代码自行调整
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
<param name="globalDataFilter"></param>
|
||||
<param name="assemblies"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IBaseRepository.AsType(System.Type)">
|
||||
<summary>
|
||||
动态Type,在使用 Repository<object> 后使用本方法,指定实体类型
|
||||
|
@ -250,6 +250,45 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
|
||||
var t11 = select.Where(a => a.Type.Name.Length > 0).ToList(true);
|
||||
var t21 = select.Where(a => a.Type.Parent.Name.Length > 0).ToList(true);
|
||||
|
||||
g.mysql.Delete<District>().Where("1=1").ExecuteAffrows();
|
||||
var repo = g.mysql.GetRepository<District>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.Insert(new District
|
||||
{
|
||||
Code = "001",
|
||||
Name = "001_name",
|
||||
Childs = new List<District>(new[] {
|
||||
new District{
|
||||
Code = "001_01",
|
||||
Name = "001_01_name"
|
||||
},
|
||||
new District{
|
||||
Code = "001_02",
|
||||
Name = "001_02_name"
|
||||
}
|
||||
})
|
||||
});
|
||||
var ddd = g.mysql.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
|
||||
Assert.Equal(1, ddd.Count);
|
||||
Assert.Equal(2, ddd[0].Childs.Count);
|
||||
}
|
||||
public class District
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public string ParentCode { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public District Parent { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<District> Childs { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void ToDictionary()
|
||||
|
@ -191,6 +191,45 @@ namespace FreeSql.Tests.Odbc.Dameng
|
||||
|
||||
var t11 = select.Where(a => a.Type.Name.Length > 0).ToList(true);
|
||||
var t21 = select.Where(a => a.Type.Parent.Name.Length > 0).ToList(true);
|
||||
|
||||
g.dameng.Delete<District>().Where("1=1").ExecuteAffrows();
|
||||
var repo = g.dameng.GetRepository<District>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.Insert(new District
|
||||
{
|
||||
Code = "001",
|
||||
Name = "001_name",
|
||||
Childs = new List<District>(new[] {
|
||||
new District{
|
||||
Code = "001_01",
|
||||
Name = "001_01_name"
|
||||
},
|
||||
new District{
|
||||
Code = "001_02",
|
||||
Name = "001_02_name"
|
||||
}
|
||||
})
|
||||
});
|
||||
var ddd = g.dameng.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
|
||||
Assert.Equal(1, ddd.Count);
|
||||
Assert.Equal(2, ddd[0].Childs.Count);
|
||||
}
|
||||
public class District
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public string ParentCode { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public District Parent { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<District> Childs { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void ToDictionary()
|
||||
|
@ -182,6 +182,45 @@ namespace FreeSql.Tests.Odbc.Default
|
||||
|
||||
var t11 = select.Where(a => a.Type.Name.Length > 0).ToList(true);
|
||||
var t21 = select.Where(a => a.Type.Parent.Name.Length > 0).ToList(true);
|
||||
|
||||
g.odbc.Delete<District>().Where("1=1").ExecuteAffrows();
|
||||
var repo = g.odbc.GetRepository<District>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.Insert(new District
|
||||
{
|
||||
Code = "001",
|
||||
Name = "001_name",
|
||||
Childs = new List<District>(new[] {
|
||||
new District{
|
||||
Code = "001_01",
|
||||
Name = "001_01_name"
|
||||
},
|
||||
new District{
|
||||
Code = "001_02",
|
||||
Name = "001_02_name"
|
||||
}
|
||||
})
|
||||
});
|
||||
var ddd = g.odbc.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
|
||||
Assert.Equal(1, ddd.Count);
|
||||
Assert.Equal(2, ddd[0].Childs.Count);
|
||||
}
|
||||
public class District
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public string ParentCode { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public District Parent { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<District> Childs { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void ToDictionary()
|
||||
|
@ -291,6 +291,45 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
|
||||
var t11 = select.Where(a => a.Type.Name.Length > 0).ToList(true);
|
||||
var t21 = select.Where(a => a.Type.Parent.Name.Length > 0).ToList(true);
|
||||
|
||||
g.mysql.Delete<District>().Where("1=1").ExecuteAffrows();
|
||||
var repo = g.mysql.GetRepository<District>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.Insert(new District
|
||||
{
|
||||
Code = "001",
|
||||
Name = "001_name",
|
||||
Childs = new List<District>(new[] {
|
||||
new District{
|
||||
Code = "001_01",
|
||||
Name = "001_01_name"
|
||||
},
|
||||
new District{
|
||||
Code = "001_02",
|
||||
Name = "001_02_name"
|
||||
}
|
||||
})
|
||||
});
|
||||
var ddd = g.mysql.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
|
||||
Assert.Equal(1, ddd.Count);
|
||||
Assert.Equal(2, ddd[0].Childs.Count);
|
||||
}
|
||||
public class District
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public string ParentCode { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public District Parent { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<District> Childs { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void ToDictionary()
|
||||
|
@ -191,6 +191,45 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
|
||||
var t11 = select.Where(a => a.Type.Name.Length > 0).ToList(true);
|
||||
var t21 = select.Where(a => a.Type.Parent.Name.Length > 0).ToList(true);
|
||||
|
||||
g.oracle.Delete<District>().Where("1=1").ExecuteAffrows();
|
||||
var repo = g.oracle.GetRepository<District>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.Insert(new District
|
||||
{
|
||||
Code = "001",
|
||||
Name = "001_name",
|
||||
Childs = new List<District>(new[] {
|
||||
new District{
|
||||
Code = "001_01",
|
||||
Name = "001_01_name"
|
||||
},
|
||||
new District{
|
||||
Code = "001_02",
|
||||
Name = "001_02_name"
|
||||
}
|
||||
})
|
||||
});
|
||||
var ddd = g.oracle.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
|
||||
Assert.Equal(1, ddd.Count);
|
||||
Assert.Equal(2, ddd[0].Childs.Count);
|
||||
}
|
||||
public class District
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public string ParentCode { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public District Parent { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<District> Childs { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void ToDictionary()
|
||||
|
@ -267,6 +267,45 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
|
||||
var t11 = select.Where(a => a.Type.Name.Length > 0).ToList(true);
|
||||
var t21 = select.Where(a => a.Type.Parent.Name.Length > 0).ToList(true);
|
||||
|
||||
g.pgsql.Delete<District>().Where("1=1").ExecuteAffrows();
|
||||
var repo = g.pgsql.GetRepository<District>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.Insert(new District
|
||||
{
|
||||
Code = "001",
|
||||
Name = "001_name",
|
||||
Childs = new List<District>(new[] {
|
||||
new District{
|
||||
Code = "001_01",
|
||||
Name = "001_01_name"
|
||||
},
|
||||
new District{
|
||||
Code = "001_02",
|
||||
Name = "001_02_name"
|
||||
}
|
||||
})
|
||||
});
|
||||
var ddd = g.pgsql.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
|
||||
Assert.Equal(1, ddd.Count);
|
||||
Assert.Equal(2, ddd[0].Childs.Count);
|
||||
}
|
||||
public class District
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public string ParentCode { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public District Parent { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<District> Childs { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void ToDictionary()
|
||||
|
@ -181,6 +181,45 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
|
||||
var t11 = select.Where(a => a.Type.Name.Length > 0).ToList(true);
|
||||
var t21 = select.Where(a => a.Type.Parent.Name.Length > 0).ToList(true);
|
||||
|
||||
g.sqlserver.Delete<District>().Where("1=1").ExecuteAffrows();
|
||||
var repo = g.sqlserver.GetRepository<District>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.Insert(new District
|
||||
{
|
||||
Code = "001",
|
||||
Name = "001_name",
|
||||
Childs = new List<District>(new[] {
|
||||
new District{
|
||||
Code = "001_01",
|
||||
Name = "001_01_name"
|
||||
},
|
||||
new District{
|
||||
Code = "001_02",
|
||||
Name = "001_02_name"
|
||||
}
|
||||
})
|
||||
});
|
||||
var ddd = g.sqlserver.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
|
||||
Assert.Equal(1, ddd.Count);
|
||||
Assert.Equal(2, ddd[0].Childs.Count);
|
||||
}
|
||||
public class District
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public string ParentCode { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public District Parent { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<District> Childs { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void ToDictionary()
|
||||
|
@ -182,6 +182,45 @@ namespace FreeSql.Tests.MsAccess
|
||||
|
||||
var t11 = select.Where(a => a.Type.Name.Length > 0).ToList(true);
|
||||
var t21 = select.Where(a => a.Type.Parent.Name.Length > 0).ToList(true);
|
||||
|
||||
g.msaccess.Delete<District>().Where("1=1").ExecuteAffrows();
|
||||
var repo = g.msaccess.GetRepository<District>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.Insert(new District
|
||||
{
|
||||
Code = "001",
|
||||
Name = "001_name",
|
||||
Childs = new List<District>(new[] {
|
||||
new District{
|
||||
Code = "001_01",
|
||||
Name = "001_01_name"
|
||||
},
|
||||
new District{
|
||||
Code = "001_02",
|
||||
Name = "001_02_name"
|
||||
}
|
||||
})
|
||||
});
|
||||
var ddd = g.msaccess.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
|
||||
Assert.Equal(1, ddd.Count);
|
||||
Assert.Equal(2, ddd[0].Childs.Count);
|
||||
}
|
||||
public class District
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public string ParentCode { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public District Parent { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<District> Childs { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void ToDictionary()
|
||||
|
@ -291,6 +291,45 @@ namespace FreeSql.Tests.MySql
|
||||
|
||||
var t11 = select.Where(a => a.Type.Name.Length > 0).ToList(true);
|
||||
var t21 = select.Where(a => a.Type.Parent.Name.Length > 0).ToList(true);
|
||||
|
||||
g.mysql.Delete<District>().Where("1=1").ExecuteAffrows();
|
||||
var repo = g.mysql.GetRepository<District>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.Insert(new District
|
||||
{
|
||||
Code = "001",
|
||||
Name = "001_name",
|
||||
Childs = new List<District>(new[] {
|
||||
new District{
|
||||
Code = "001_01",
|
||||
Name = "001_01_name"
|
||||
},
|
||||
new District{
|
||||
Code = "001_02",
|
||||
Name = "001_02_name"
|
||||
}
|
||||
})
|
||||
});
|
||||
var ddd = g.mysql.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
|
||||
Assert.Equal(1, ddd.Count);
|
||||
Assert.Equal(2, ddd[0].Childs.Count);
|
||||
}
|
||||
public class District
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public string ParentCode { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public District Parent { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<District> Childs { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void ToDictionary()
|
||||
|
@ -191,6 +191,45 @@ namespace FreeSql.Tests.Oracle
|
||||
|
||||
var t11 = select.Where(a => a.Type.Name.Length > 0).ToList(true);
|
||||
var t21 = select.Where(a => a.Type.Parent.Name.Length > 0).ToList(true);
|
||||
|
||||
g.oracle.Delete<District>().Where("1=1").ExecuteAffrows();
|
||||
var repo = g.oracle.GetRepository<District>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.Insert(new District
|
||||
{
|
||||
Code = "001",
|
||||
Name = "001_name",
|
||||
Childs = new List<District>(new[] {
|
||||
new District{
|
||||
Code = "001_01",
|
||||
Name = "001_01_name"
|
||||
},
|
||||
new District{
|
||||
Code = "001_02",
|
||||
Name = "001_02_name"
|
||||
}
|
||||
})
|
||||
});
|
||||
var ddd = g.oracle.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
|
||||
Assert.Equal(1, ddd.Count);
|
||||
Assert.Equal(2, ddd[0].Childs.Count);
|
||||
}
|
||||
public class District
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public string ParentCode { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public District Parent { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<District> Childs { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void ToDictionary()
|
||||
|
@ -267,6 +267,45 @@ namespace FreeSql.Tests.PostgreSQL
|
||||
|
||||
var t11 = select.Where(a => a.Type.Name.Length > 0).ToList(true);
|
||||
var t21 = select.Where(a => a.Type.Parent.Name.Length > 0).ToList(true);
|
||||
|
||||
g.pgsql.Delete<District>().Where("1=1").ExecuteAffrows();
|
||||
var repo = g.pgsql.GetRepository<District>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.Insert(new District
|
||||
{
|
||||
Code = "001",
|
||||
Name = "001_name",
|
||||
Childs = new List<District>(new[] {
|
||||
new District{
|
||||
Code = "001_01",
|
||||
Name = "001_01_name"
|
||||
},
|
||||
new District{
|
||||
Code = "001_02",
|
||||
Name = "001_02_name"
|
||||
}
|
||||
})
|
||||
});
|
||||
var ddd = g.pgsql.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
|
||||
Assert.Equal(1, ddd.Count);
|
||||
Assert.Equal(2, ddd[0].Childs.Count);
|
||||
}
|
||||
public class District
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public string ParentCode { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public District Parent { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<District> Childs { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void ToDictionary()
|
||||
|
@ -191,6 +191,45 @@ namespace FreeSql.Tests.SqlServer
|
||||
|
||||
var t11 = select.Where(a => a.Type.Name.Length > 0).ToList(true);
|
||||
var t21 = select.Where(a => a.Type.Parent.Name.Length > 0).ToList(true);
|
||||
|
||||
g.sqlserver.Delete<District>().Where("1=1").ExecuteAffrows();
|
||||
var repo = g.sqlserver.GetRepository<District>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.Insert(new District
|
||||
{
|
||||
Code = "001",
|
||||
Name = "001_name",
|
||||
Childs = new List<District>(new[] {
|
||||
new District{
|
||||
Code = "001_01",
|
||||
Name = "001_01_name"
|
||||
},
|
||||
new District{
|
||||
Code = "001_02",
|
||||
Name = "001_02_name"
|
||||
}
|
||||
})
|
||||
});
|
||||
var ddd = g.sqlserver.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
|
||||
Assert.Equal(1, ddd.Count);
|
||||
Assert.Equal(2, ddd[0].Childs.Count);
|
||||
}
|
||||
public class District
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public string ParentCode { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public District Parent { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<District> Childs { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void ToDictionary()
|
||||
|
@ -208,6 +208,45 @@ namespace FreeSql.Tests.Sqlite
|
||||
|
||||
var t11 = select.Where(a => a.Type.Name.Length > 0).ToList(true);
|
||||
var t21 = select.Where(a => a.Type.Parent.Name.Length > 0).ToList(true);
|
||||
|
||||
g.sqlite.Delete<District>().Where("1=1").ExecuteAffrows();
|
||||
var repo = g.sqlite.GetRepository<District>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.Insert(new District
|
||||
{
|
||||
Code = "001",
|
||||
Name = "001_name",
|
||||
Childs = new List<District>(new[] {
|
||||
new District{
|
||||
Code = "001_01",
|
||||
Name = "001_01_name"
|
||||
},
|
||||
new District{
|
||||
Code = "001_02",
|
||||
Name = "001_02_name"
|
||||
}
|
||||
})
|
||||
});
|
||||
var ddd = g.sqlite.Select<District>().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList();
|
||||
Assert.Equal(1, ddd.Count);
|
||||
Assert.Equal(2, ddd[0].Childs.Count);
|
||||
}
|
||||
public class District
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public string ParentCode { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public District Parent { get; set; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<District> Childs { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void ToDictionary()
|
||||
|
@ -712,7 +712,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
string key = null;
|
||||
if (tbref.RefColumns.Count == 1)
|
||||
{
|
||||
key = _orm.GetEntityValueWithPropertyName(tbref.RefEntityType, nav, tbref.RefColumns[0].CsName).ToString();
|
||||
key = _orm.GetEntityValueWithPropertyName(tbref.RefEntityType, nav, tbref.RefColumns[0].CsName)?.ToString() ?? "";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1043,7 +1043,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
string key = null;
|
||||
if (tbref.Columns.Count == 1)
|
||||
key = _orm.GetEntityValueWithPropertyName(tbref.RefMiddleEntityType, midList[a], tbref.MiddleColumns[0].CsName).ToString();
|
||||
key = _orm.GetEntityValueWithPropertyName(tbref.RefMiddleEntityType, midList[a], tbref.MiddleColumns[0].CsName)?.ToString() ?? "";
|
||||
else
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
Loading…
x
Reference in New Issue
Block a user