diff --git a/FreeSql.Tests/MySql/Curd/MySqlSelectTest.cs b/FreeSql.Tests/MySql/Curd/MySqlSelectTest.cs index cbe5383c..78292577 100644 --- a/FreeSql.Tests/MySql/Curd/MySqlSelectTest.cs +++ b/FreeSql.Tests/MySql/Curd/MySqlSelectTest.cs @@ -923,6 +923,15 @@ namespace FreeSql.Tests.MySql { public int model2111Idaaa { get; set; } public string title { get; set; } + + public List childs2 { get; set; } + } + public class TestInclude_OneToManyModel4 { + [Column(IsIdentity = true)] + public int id { get; set; } + + public int model3333Id333 { get; set; } + public string title444 { get; set; } } [Fact] @@ -932,17 +941,32 @@ namespace FreeSql.Tests.MySql { var model2 = new TestInclude_OneToManyModel2 { model2id = model1.id, m2setting = DateTime.Now.Second.ToString() }; g.mysql.Insert(model2).ExecuteAffrows(); - var model3s = new[] { - new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__111" }, - new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__222" }, - new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__333" } + var model3_1 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__111" }; + model3_1.id = (int)g.mysql.Insert(model3_1).ExecuteIdentity(); + var model3_2 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__222" }; + model3_2.id = (int)g.mysql.Insert(model3_2).ExecuteIdentity(); + var model3_3 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__333" }; + model3_3.id = (int)g.mysql.Insert(model3_2).ExecuteIdentity(); + + var model4s = new[] { + new TestInclude_OneToManyModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__111" }, + new TestInclude_OneToManyModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__222" }, + new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__111" }, + new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__222" }, + new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__333" } }; - Assert.Equal(3, g.mysql.Insert(model3s).ExecuteAffrows()); + Assert.Equal(5, g.mysql.Insert(model4s).ExecuteAffrows()); var t1 = g.mysql.Select() .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id)) .Where(a => a.id <= model1.id) .ToList(); + + var t2 = g.mysql.Select() + .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id), + then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id))) + .Where(a => a.id <= model1.id) + .ToList(); } [Fact] public void Include_OneToChilds() { diff --git a/FreeSql.Tests/Oracle/Curd/OracleSelectTest.cs b/FreeSql.Tests/Oracle/Curd/OracleSelectTest.cs index 8879cb26..3c09e1d3 100644 --- a/FreeSql.Tests/Oracle/Curd/OracleSelectTest.cs +++ b/FreeSql.Tests/Oracle/Curd/OracleSelectTest.cs @@ -816,6 +816,15 @@ namespace FreeSql.Tests.Oracle { public int model2111Idaaa { get; set; } public string title { get; set; } + + public List childs2 { get; set; } + } + public class TiOtmModel4 { + [Column(IsIdentity = true)] + public int id { get; set; } + + public int model3333Id333 { get; set; } + public string title444 { get; set; } } [Fact] @@ -825,17 +834,32 @@ namespace FreeSql.Tests.Oracle { var model2 = new TiOtmModel2 { model2id = model1.id, m2setting = DateTime.Now.Second.ToString() }; g.oracle.Insert(model2).ExecuteAffrows(); - var model3s = new[] { - new TiOtmModel3{ model2111Idaaa = model1.id, title = "testmodel3__111" }, - new TiOtmModel3{ model2111Idaaa = model1.id, title = "testmodel3__222" }, - new TiOtmModel3{ model2111Idaaa = model1.id, title = "testmodel3__333" } + var model3_1 = new TiOtmModel3 { model2111Idaaa = model1.id, title = "testmodel3__111" }; + model3_1.id = (int)g.oracle.Insert(model3_1).ExecuteIdentity(); + var model3_2 = new TiOtmModel3 { model2111Idaaa = model1.id, title = "testmodel3__222" }; + model3_2.id = (int)g.oracle.Insert(model3_2).ExecuteIdentity(); + var model3_3 = new TiOtmModel3 { model2111Idaaa = model1.id, title = "testmodel3__333" }; + model3_3.id = (int)g.oracle.Insert(model3_2).ExecuteIdentity(); + + var model4s = new[] { + new TiOtmModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__111" }, + new TiOtmModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__222" }, + new TiOtmModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__111" }, + new TiOtmModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__222" }, + new TiOtmModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__333" } }; - Assert.Equal(3, g.oracle.Insert(model3s).ExecuteAffrows()); + Assert.Equal(5, g.oracle.Insert(model4s).ExecuteAffrows()); var t1 = g.oracle.Select() .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id)) .Where(a => a.id <= model1.id) .ToList(); + + var t2 = g.oracle.Select() + .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id), + then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id))) + .Where(a => a.id <= model1.id) + .ToList(); } [Fact] public void Include_OneToChilds() { diff --git a/FreeSql.Tests/PostgreSQL/Curd/PostgreSQLSelectTest.cs b/FreeSql.Tests/PostgreSQL/Curd/PostgreSQLSelectTest.cs index 41249f7b..088b4545 100644 --- a/FreeSql.Tests/PostgreSQL/Curd/PostgreSQLSelectTest.cs +++ b/FreeSql.Tests/PostgreSQL/Curd/PostgreSQLSelectTest.cs @@ -882,6 +882,15 @@ namespace FreeSql.Tests.PostgreSQL { public int model2111Idaaa { get; set; } public string title { get; set; } + + public List childs2 { get; set; } + } + public class TestInclude_OneToManyModel4 { + [Column(IsIdentity = true)] + public int id { get; set; } + + public int model3333Id333 { get; set; } + public string title444 { get; set; } } [Fact] @@ -891,17 +900,32 @@ namespace FreeSql.Tests.PostgreSQL { var model2 = new TestInclude_OneToManyModel2 { model2id = model1.id, m2setting = DateTime.Now.Second.ToString() }; g.pgsql.Insert(model2).ExecuteAffrows(); - var model3s = new[] { - new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__111" }, - new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__222" }, - new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__333" } + var model3_1 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__111" }; + model3_1.id = (int)g.pgsql.Insert(model3_1).ExecuteIdentity(); + var model3_2 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__222" }; + model3_2.id = (int)g.pgsql.Insert(model3_2).ExecuteIdentity(); + var model3_3 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__333" }; + model3_3.id = (int)g.pgsql.Insert(model3_2).ExecuteIdentity(); + + var model4s = new[] { + new TestInclude_OneToManyModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__111" }, + new TestInclude_OneToManyModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__222" }, + new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__111" }, + new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__222" }, + new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__333" } }; - Assert.Equal(3, g.pgsql.Insert(model3s).ExecuteAffrows()); + Assert.Equal(5, g.pgsql.Insert(model4s).ExecuteAffrows()); var t1 = g.pgsql.Select() .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id)) .Where(a => a.id <= model1.id) .ToList(); + + var t2 = g.pgsql.Select() + .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id), + then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id))) + .Where(a => a.id <= model1.id) + .ToList(); } [Fact] public void Include_OneToChilds() { diff --git a/FreeSql.Tests/SqlServer/Curd/SqlServerSelectTest.cs b/FreeSql.Tests/SqlServer/Curd/SqlServerSelectTest.cs index 6aadf12b..3e37bf8b 100644 --- a/FreeSql.Tests/SqlServer/Curd/SqlServerSelectTest.cs +++ b/FreeSql.Tests/SqlServer/Curd/SqlServerSelectTest.cs @@ -813,6 +813,15 @@ namespace FreeSql.Tests.SqlServer { public int model2111Idaaa { get; set; } public string title { get; set; } + + public List childs2 { get; set; } + } + public class TestInclude_OneToManyModel4 { + [Column(IsIdentity = true)] + public int id { get; set; } + + public int model3333Id333 { get; set; } + public string title444 { get; set; } } [Fact] @@ -822,17 +831,32 @@ namespace FreeSql.Tests.SqlServer { var model2 = new TestInclude_OneToManyModel2 { model2id = model1.id, m2setting = DateTime.Now.Second.ToString() }; _sqlserverFixture.SqlServer.Insert(model2).ExecuteAffrows(); - var model3s = new[] { - new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__111" }, - new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__222" }, - new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__333" } + var model3_1 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__111" }; + model3_1.id = (int)_sqlserverFixture.SqlServer.Insert(model3_1).ExecuteIdentity(); + var model3_2 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__222" }; + model3_2.id = (int)_sqlserverFixture.SqlServer.Insert(model3_2).ExecuteIdentity(); + var model3_3 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__333" }; + model3_3.id = (int)_sqlserverFixture.SqlServer.Insert(model3_2).ExecuteIdentity(); + + var model4s = new[] { + new TestInclude_OneToManyModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__111" }, + new TestInclude_OneToManyModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__222" }, + new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__111" }, + new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__222" }, + new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__333" } }; - Assert.Equal(3, _sqlserverFixture.SqlServer.Insert(model3s).ExecuteAffrows()); + Assert.Equal(5, _sqlserverFixture.SqlServer.Insert(model4s).ExecuteAffrows()); var t1 = _sqlserverFixture.SqlServer.Select() .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id)) .Where(a => a.id <= model1.id) .ToList(); + + var t2 = _sqlserverFixture.SqlServer.Select() + .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id), + then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id))) + .Where(a => a.id <= model1.id) + .ToList(); } [Fact] public void Include_OneToChilds() { diff --git a/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs b/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs index 106561f6..cd7ea897 100644 --- a/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs +++ b/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs @@ -779,6 +779,15 @@ namespace FreeSql.Tests.Sqlite { public int model2111Idaaa { get; set; } public string title { get; set; } + + public List childs2 { get; set; } + } + public class TestInclude_OneToManyModel4 { + [Column(IsIdentity = true)] + public int id { get; set; } + + public int model3333Id333 { get; set; } + public string title444 { get; set; } } [Fact] @@ -788,15 +797,30 @@ namespace FreeSql.Tests.Sqlite { var model2 = new TestInclude_OneToManyModel2 { model2id = model1.id, m2setting = DateTime.Now.Second.ToString() }; g.sqlite.Insert(model2).ExecuteAffrows(); - var model3s = new [] { - new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__111" }, - new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__222" }, - new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__333" } + var model3_1 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__111" }; + model3_1.id = (int)g.sqlite.Insert(model3_1).ExecuteIdentity(); + var model3_2 =new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__222" }; + model3_2.id = (int)g.sqlite.Insert(model3_2).ExecuteIdentity(); + var model3_3 = new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__333" }; + model3_3.id = (int)g.sqlite.Insert(model3_2).ExecuteIdentity(); + + var model4s = new[] { + new TestInclude_OneToManyModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__111" }, + new TestInclude_OneToManyModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__222" }, + new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__111" }, + new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__222" }, + new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__333" } }; - Assert.Equal(3, g.sqlite.Insert(model3s).ExecuteAffrows()); + Assert.Equal(5, g.sqlite.Insert(model4s).ExecuteAffrows()); var t1 = g.sqlite.Select() - .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id && m3.title == a.model2.m2setting)) + .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id)) + .Where(a => a.id <= model1.id) + .ToList(); + + var t2 = g.sqlite.Select() + .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id), + then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id))) .Where(a => a.id <= model1.id) .ToList(); }