mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 增加 IncludeMany 贪婪加载的时候可指定子表的字段,避免查询子表所有字段;
This commit is contained in:
parent
769c1f020c
commit
1083f371a9
@ -87,16 +87,6 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
public virtual ICollection<Tag> Tags { get; set; }
|
||||
}
|
||||
|
||||
[Table(Name = "TestInfoT1")]
|
||||
class TestInfo
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int TypeGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsSelect()
|
||||
@ -183,20 +173,10 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
|
||||
var t0 = select.Limit(50).ToList();
|
||||
|
||||
|
||||
var t1 = g.mysql.Select<TestInfo>().Where("").Where(a => a.Id > 0).Skip(100).Limit(200).ToSql();
|
||||
var t2 = g.mysql.Select<TestInfo>().As("b").Where("").Where(a => a.Id > 0).Skip(100).Limit(200).ToSql();
|
||||
|
||||
|
||||
var sql1 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).ToSql();
|
||||
var sql2 = select.LeftJoin<TestTypeInfo>((a, b) => a.TypeGuid == b.Guid && b.Name == "111").ToSql();
|
||||
var sql3 = select.LeftJoin("TestTypeInfo b on b.Guid = a.TypeGuid").ToSql();
|
||||
|
||||
//g.mysql.Select<TestInfo, TestTypeInfo, TestTypeParentInfo>().Join((a, b, c) => new Model.JoinResult3(
|
||||
// Model.JoinType.LeftJoin, a.TypeGuid == b.Guid,
|
||||
// Model.JoinType.InnerJoin, c.Id == b.ParentId && c.Name == "xxx")
|
||||
//);
|
||||
|
||||
//var sql4 = select.From<TestTypeInfo, TestTypeParentInfo>((a, b, c) => new SelectFrom()
|
||||
// .InnerJoin(a.TypeGuid == b.Guid)
|
||||
// .LeftJoin(c.Id == b.ParentId)
|
||||
@ -238,37 +218,6 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
});
|
||||
|
||||
var ttt122 = g.mysql.Select<TestTypeParentInfo>().Where(a => a.Id > 0).ToSql();
|
||||
var sql5 = g.mysql.Select<TestInfo>().From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s).Where((a, b, c) => a.Id == b.ParentId).ToSql();
|
||||
var t11112 = g.mysql.Select<TestInfo>().ToList(a => new
|
||||
{
|
||||
a.Id,
|
||||
a.Title,
|
||||
a.Type,
|
||||
ccc = new { a.Id, a.Title },
|
||||
tp = a.Type,
|
||||
tp2 = new
|
||||
{
|
||||
a.Id,
|
||||
tp2 = a.Type.Name
|
||||
},
|
||||
tp3 = new
|
||||
{
|
||||
a.Id,
|
||||
tp33 = new
|
||||
{
|
||||
a.Id
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var t100 = g.mysql.Select<TestInfo>().Where("").Where(a => a.Id > 0).Skip(100).Limit(200).ToList();
|
||||
var t101 = g.mysql.Select<TestInfo>().As("b").Where("").Where(a => a.Id > 0).Skip(100).Limit(200).ToList();
|
||||
|
||||
|
||||
var t1111 = g.mysql.Select<TestInfo>().ToList(a => new { a.Id, a.Title, a.Type });
|
||||
|
||||
var t2222 = g.mysql.Select<TestInfo>().ToList(a => new { a.Id, a.Title, a.Type.Name });
|
||||
|
||||
g.mysql.Insert<TestGuidIdToList>().AppendData(new TestGuidIdToList()).ExecuteAffrows();
|
||||
var testGuidId5 = g.mysql.Select<TestGuidIdToList>().ToList();
|
||||
@ -784,7 +733,6 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
});
|
||||
|
||||
var testpid1 = g.mysql.Insert<TestTypeInfo>().AppendData(new TestTypeInfo { Name = "Name" + DateTime.Now.ToString("yyyyMMddHHmmss") }).ExecuteIdentity();
|
||||
g.mysql.Insert<TestInfo>().AppendData(new TestInfo { Title = "Title" + DateTime.Now.ToString("yyyyMMddHHmmss"), CreateTime = DateTime.Now, TypeGuid = (int)testpid1 }).ExecuteAffrows();
|
||||
|
||||
var aggsql1 = select
|
||||
.GroupBy(a => a.Title)
|
||||
@ -1003,9 +951,9 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topicAsTable1` a LEFT JOIN TestTypeInfo b on b.Guid = a.TypeGuid", sql);
|
||||
|
||||
query = select.LeftJoin("TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = @bname", new { bname = "xxx" }).AsTable(tableRule);
|
||||
query = select.LeftJoin("TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = ?bname", new { bname = "xxx" }).AsTable(tableRule);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topicAsTable1` a LEFT JOIN TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = @bname", sql);
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topicAsTable1` a LEFT JOIN TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = ?bname", sql);
|
||||
}
|
||||
|
||||
public class TestInclude_OneToManyModel1
|
||||
@ -1100,6 +1048,40 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id)))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at0 = g.mysql.Select<TestInclude_OneToManyModel2>()
|
||||
.IncludeMany(a => a.childs.Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at1 = g.mysql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at2 = g.mysql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TestInclude_OneToManyModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at00 = g.mysql.Select<TestInclude_OneToManyModel2>()
|
||||
.IncludeMany(a => a.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at11 = g.mysql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at22 = g.mysql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TestInclude_OneToManyModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public class TestInclude_OneToManyModel11
|
||||
@ -1117,6 +1099,8 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string m2setting { get; set; }
|
||||
public string aaa { get; set; }
|
||||
public string bbb { get; set; }
|
||||
public List<TestInclude_OneToManyModel33> childs { get; set; }
|
||||
}
|
||||
public class TestInclude_OneToManyModel33
|
||||
@ -1131,7 +1115,7 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
public void Include_OneToMany2()
|
||||
{
|
||||
string setting = "x";
|
||||
var model2 = new TestInclude_OneToManyModel22 { m2setting = DateTime.Now.Second.ToString() };
|
||||
var model2 = new TestInclude_OneToManyModel22 { m2setting = DateTime.Now.Second.ToString(), aaa = "aaa" + DateTime.Now.Second, bbb = "bbb" + DateTime.Now.Second };
|
||||
model2.id = (int)g.mysql.Insert(model2).ExecuteIdentity();
|
||||
|
||||
var model3s = new[]
|
||||
@ -1156,6 +1140,20 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at1 = g.mysql.Select<TestInclude_OneToManyModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TestInclude_OneToManyModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
var at11 = g.mysql.Select<TestInclude_OneToManyModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TestInclude_OneToManyModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1253,6 +1251,59 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
.IncludeMany(a => a.Songs.Take(1))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
// --- Select ---
|
||||
|
||||
var atags0 = g.mysql.Select<Tag>()
|
||||
.Include(a => a.Parent)
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags1 = g.mysql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags2 = g.mysql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags3 = g.mysql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags11 = g.mysql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags22 = g.mysql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags33 = g.mysql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1357,6 +1408,61 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
// --- Select ---
|
||||
|
||||
new List<Song>(new[] { song1, song2, song3 }).IncludeMany(g.mysql, a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }));
|
||||
|
||||
var asongs1 = g.mysql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs1.Count);
|
||||
Assert.Equal(2, songs1[0].Tags.Count);
|
||||
Assert.Equal(1, songs1[1].Tags.Count);
|
||||
Assert.Equal(3, songs1[2].Tags.Count);
|
||||
|
||||
var asongs2 = g.mysql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs2.Count);
|
||||
Assert.Equal(2, songs2[0].Tags.Count);
|
||||
Assert.Equal(1, songs2[1].Tags.Count);
|
||||
Assert.Equal(3, songs2[2].Tags.Count);
|
||||
|
||||
var atags3 = g.mysql.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
|
||||
var asongs11 = g.mysql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs11.Count);
|
||||
Assert.Equal(1, songs11[0].Tags.Count);
|
||||
Assert.Equal(1, songs11[1].Tags.Count);
|
||||
Assert.Equal(1, songs11[2].Tags.Count);
|
||||
|
||||
var asongs22 = g.mysql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs22.Count);
|
||||
Assert.Equal(1, songs22[0].Tags.Count);
|
||||
Assert.Equal(1, songs22[1].Tags.Count);
|
||||
Assert.Equal(1, songs22[2].Tags.Count);
|
||||
|
||||
var atags33 = g.mysql.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
public class ToDel1Pk
|
||||
|
@ -425,10 +425,6 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a LEFT JOIN TestTypeInfo b on b.Guid = a.TypeGuid", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.LeftJoin("TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = ?", new { bname = "xxx" });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a LEFT JOIN TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = ?", sql);
|
||||
query.ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void InnerJoin()
|
||||
@ -494,11 +490,6 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a INNER JOIN TestTypeInfo b on b.Guid = a.TypeGuid", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.InnerJoin("TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = ?", new { bname = "xxx" });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a INNER JOIN TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = ?", sql);
|
||||
query.ToList();
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void RightJoin()
|
||||
@ -564,11 +555,6 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a RIGHT JOIN TestTypeInfo b on b.Guid = a.TypeGuid", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.RightJoin("TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = ?", new { bname = "xxx" });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a RIGHT JOIN TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = ?", sql);
|
||||
query.ToList();
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void Where()
|
||||
@ -635,11 +621,6 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a, `TestTypeInfo` b, `TestTypeParentInfo` c WHERE (a.`Id` = 10 AND c.`Name` = 'xxx') AND (b.`ParentId` = 20)", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.Where("a.clicks > 100 and a.id = ?", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a WHERE (a.clicks > 100 and a.id = ?)", sql);
|
||||
query.ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void WhereIf()
|
||||
@ -683,12 +664,6 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a, `TestTypeInfo` b, `TestTypeParentInfo` c WHERE (a.`Id` = 10 AND c.`Name` = 'xxx') AND (b.`ParentId` = 20)", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.WhereIf(true, "a.clicks > 100 and a.id = ?", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a WHERE (a.clicks > 100 and a.id = ?)", sql);
|
||||
query.ToList();
|
||||
|
||||
// ==========================================WhereIf(false)
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a.Type<70><65>a.Type.Parent <20><><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -729,12 +704,6 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
sql = query2.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a, `TestTypeInfo` b, `TestTypeParentInfo` c", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.WhereIf(false, "a.clicks > 100 and a.id = ?", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a", sql);
|
||||
query.ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void WhereExists()
|
||||
@ -1090,6 +1059,40 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id)))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at0 = g.mysql.Select<TestInclude_OneToManyModel2>()
|
||||
.IncludeMany(a => a.childs.Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at1 = g.mysql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at2 = g.mysql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TestInclude_OneToManyModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at00 = g.mysql.Select<TestInclude_OneToManyModel2>()
|
||||
.IncludeMany(a => a.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at11 = g.mysql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at22 = g.mysql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TestInclude_OneToManyModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public class TestInclude_OneToManyModel11
|
||||
@ -1107,6 +1110,8 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string m2setting { get; set; }
|
||||
public string aaa { get; set; }
|
||||
public string bbb { get; set; }
|
||||
public List<TestInclude_OneToManyModel33> childs { get; set; }
|
||||
}
|
||||
public class TestInclude_OneToManyModel33
|
||||
@ -1121,7 +1126,7 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
public void Include_OneToMany2()
|
||||
{
|
||||
string setting = "x";
|
||||
var model2 = new TestInclude_OneToManyModel22 { m2setting = DateTime.Now.Second.ToString() };
|
||||
var model2 = new TestInclude_OneToManyModel22 { m2setting = DateTime.Now.Second.ToString(), aaa = "aaa" + DateTime.Now.Second, bbb = "bbb" + DateTime.Now.Second };
|
||||
model2.id = (int)g.mysql.Insert(model2).ExecuteIdentity();
|
||||
|
||||
var model3s = new[]
|
||||
@ -1146,6 +1151,20 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at1 = g.mysql.Select<TestInclude_OneToManyModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TestInclude_OneToManyModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
var at11 = g.mysql.Select<TestInclude_OneToManyModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TestInclude_OneToManyModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1243,6 +1262,59 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
.IncludeMany(a => a.Songs.Take(1))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
// --- Select ---
|
||||
|
||||
var atags0 = g.mysql.Select<Tag>()
|
||||
.Include(a => a.Parent)
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags1 = g.mysql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags2 = g.mysql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags3 = g.mysql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags11 = g.mysql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags22 = g.mysql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags33 = g.mysql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1347,6 +1419,61 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
// --- Select ---
|
||||
|
||||
new List<Song>(new[] { song1, song2, song3 }).IncludeMany(g.mysql, a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }));
|
||||
|
||||
var asongs1 = g.mysql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs1.Count);
|
||||
Assert.Equal(2, songs1[0].Tags.Count);
|
||||
Assert.Equal(1, songs1[1].Tags.Count);
|
||||
Assert.Equal(3, songs1[2].Tags.Count);
|
||||
|
||||
var asongs2 = g.mysql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs2.Count);
|
||||
Assert.Equal(2, songs2[0].Tags.Count);
|
||||
Assert.Equal(1, songs2[1].Tags.Count);
|
||||
Assert.Equal(3, songs2[2].Tags.Count);
|
||||
|
||||
var atags3 = g.mysql.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
|
||||
var asongs11 = g.mysql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs11.Count);
|
||||
Assert.Equal(1, songs11[0].Tags.Count);
|
||||
Assert.Equal(1, songs11[1].Tags.Count);
|
||||
Assert.Equal(1, songs11[2].Tags.Count);
|
||||
|
||||
var asongs22 = g.mysql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs22.Count);
|
||||
Assert.Equal(1, songs22[0].Tags.Count);
|
||||
Assert.Equal(1, songs22[1].Tags.Count);
|
||||
Assert.Equal(1, songs22[2].Tags.Count);
|
||||
|
||||
var atags33 = g.mysql.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
public class ToDel1Pk
|
||||
|
@ -136,9 +136,9 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
//items = Enumerable.Range(0, 9989).Select(a => new TopicInserts { Title = "newtitle" + a, CreateTime = DateTime.Now }).ToList();
|
||||
//Assert.Equal(9989, g.oracle.Insert<TopicInserts>(items).ExecuteAffrows());
|
||||
|
||||
var dt1 = select.Limit(10).ToDataTable();
|
||||
var dt2 = select.Limit(10).ToDataTable("id, 111222");
|
||||
var dt3 = select.Limit(10).ToDataTable(a => new { a.Id, a.Type.Name, now = DateTime.Now.ToString() });
|
||||
//var dt1 = select.ToDataTable();
|
||||
//var dt2 = select.ToDataTable("id, 111222");
|
||||
//var dt3 = select.ToDataTable(a => new { a.Id, a.Type.Name, now = DateTime.Now });
|
||||
}
|
||||
class TestDto
|
||||
{
|
||||
@ -380,9 +380,9 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.InnerJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = ?", new { bname = "xxx" });
|
||||
query = select.InnerJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", new { bname = "xxx" });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = ?", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", sql);
|
||||
query.ToList();
|
||||
|
||||
}
|
||||
@ -450,9 +450,9 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.RightJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = ?", new { bname = "xxx" });
|
||||
query = select.RightJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", new { bname = "xxx" });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = ?", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", sql);
|
||||
query.ToList();
|
||||
|
||||
}
|
||||
@ -521,9 +521,9 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.Where("a.\"CLICKS\" > 100 and a.\"ID\" = ?", new { id = 10 });
|
||||
query = select.Where("a.\"CLICKS\" > 100 and a.\"ID\" = :id", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"CLICKS\" > 100 and a.\"ID\" = ?)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"CLICKS\" > 100 and a.\"ID\" = :id)", sql);
|
||||
query.ToList();
|
||||
}
|
||||
[Fact]
|
||||
@ -569,9 +569,9 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.WhereIf(true, "a.\"CLICKS\" > 100 and a.\"ID\" = ?", new { id = 10 });
|
||||
query = select.WhereIf(true, "a.\"CLICKS\" > 100 and a.\"ID\" = :id", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"CLICKS\" > 100 and a.\"ID\" = ?)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"CLICKS\" > 100 and a.\"ID\" = :id)", sql);
|
||||
query.ToList();
|
||||
|
||||
// ==========================================WhereIf(false)
|
||||
@ -616,7 +616,7 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.WhereIf(false, "a.\"CLICKS\" > 100 and a.\"ID\" = ?", new { id = 10 });
|
||||
query = select.WhereIf(false, "a.\"CLICKS\" > 100 and a.\"ID\" = :id", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql);
|
||||
query.ToList();
|
||||
@ -975,6 +975,40 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id)))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at0 = g.oracle.Select<TiOtmModel2>()
|
||||
.IncludeMany(a => a.childs.Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TiOtmModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at1 = g.oracle.Select<TiOtmModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TiOtmModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at2 = g.oracle.Select<TiOtmModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TiOtmModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TiOtmModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at00 = g.oracle.Select<TiOtmModel2>()
|
||||
.IncludeMany(a => a.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TiOtmModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at11 = g.oracle.Select<TiOtmModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TiOtmModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at22 = g.oracle.Select<TiOtmModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TiOtmModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TiOtmModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public class TiOtmModel11
|
||||
@ -992,6 +1026,8 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string m2setting { get; set; }
|
||||
public string aaa { get; set; }
|
||||
public string bbb { get; set; }
|
||||
public List<TiOtmModel33> childs { get; set; }
|
||||
}
|
||||
public class TiOtmModel33
|
||||
@ -1006,7 +1042,7 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
public void Include_OneToMany2()
|
||||
{
|
||||
string setting = "x";
|
||||
var model2 = new TiOtmModel22 { m2setting = DateTime.Now.Second.ToString() };
|
||||
var model2 = new TiOtmModel22 { m2setting = DateTime.Now.Second.ToString(), aaa = "aaa" + DateTime.Now.Second, bbb = "bbb" + DateTime.Now.Second };
|
||||
model2.id = (int)g.oracle.Insert(model2).ExecuteIdentity();
|
||||
|
||||
var model3s = new[]
|
||||
@ -1031,6 +1067,20 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at1 = g.oracle.Select<TiOtmModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TiOtmModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
var at11 = g.oracle.Select<TiOtmModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TiOtmModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1128,6 +1178,59 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
.IncludeMany(a => a.Songs.Take(1))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
// --- Select ---
|
||||
|
||||
var atags0 = g.oracle.Select<Tag>()
|
||||
.Include(a => a.Parent)
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags1 = g.oracle.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags2 = g.oracle.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags3 = g.oracle.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags11 = g.oracle.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags22 = g.oracle.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags33 = g.oracle.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1232,6 +1335,61 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
// --- Select ---
|
||||
|
||||
new List<Song>(new[] { song1, song2, song3 }).IncludeMany(g.oracle, a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }));
|
||||
|
||||
var asongs1 = g.oracle.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs1.Count);
|
||||
Assert.Equal(2, songs1[0].Tags.Count);
|
||||
Assert.Equal(1, songs1[1].Tags.Count);
|
||||
Assert.Equal(3, songs1[2].Tags.Count);
|
||||
|
||||
var asongs2 = g.oracle.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs2.Count);
|
||||
Assert.Equal(2, songs2[0].Tags.Count);
|
||||
Assert.Equal(1, songs2[1].Tags.Count);
|
||||
Assert.Equal(3, songs2[2].Tags.Count);
|
||||
|
||||
var atags3 = g.oracle.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
|
||||
var asongs11 = g.oracle.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs11.Count);
|
||||
Assert.Equal(1, songs11[0].Tags.Count);
|
||||
Assert.Equal(1, songs11[1].Tags.Count);
|
||||
Assert.Equal(1, songs11[2].Tags.Count);
|
||||
|
||||
var asongs22 = g.oracle.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs22.Count);
|
||||
Assert.Equal(1, songs22[0].Tags.Count);
|
||||
Assert.Equal(1, songs22[1].Tags.Count);
|
||||
Assert.Equal(1, songs22[2].Tags.Count);
|
||||
|
||||
var atags33 = g.oracle.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
public class ToDel1Pk
|
||||
|
@ -389,11 +389,6 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.LeftJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = ?", new { bname = "xxx" });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = ?", sql);
|
||||
query.ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void InnerJoin()
|
||||
@ -458,12 +453,6 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a INNER JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.InnerJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = ?", new { bname = "xxx" });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a INNER JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = ?", sql);
|
||||
query.ToList();
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void RightJoin()
|
||||
@ -528,12 +517,6 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a RIGHT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\"", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.RightJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = ?", new { bname = "xxx" });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a RIGHT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = ?", sql);
|
||||
query.ToList();
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void Where()
|
||||
@ -600,9 +583,9 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.Where("a.\"clicks\" > 100 and a.\"id\" = ?", new { id = 10 });
|
||||
query = select.Where("a.\"clicks\" > 100 and a.\"id\" = @id", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"clicks\" > 100 and a.\"id\" = ?)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"clicks\" > 100 and a.\"id\" = @id)", sql);
|
||||
query.ToList();
|
||||
}
|
||||
[Fact]
|
||||
@ -648,9 +631,9 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.WhereIf(true, "a.\"clicks\" > 100 and a.\"id\" = ?", new { id = 10 });
|
||||
query = select.WhereIf(true, "a.\"clicks\" > 100 and a.\"id\" = @id", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"clicks\" > 100 and a.\"id\" = ?)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"clicks\" > 100 and a.\"id\" = @id)", sql);
|
||||
query.ToList();
|
||||
|
||||
// ==========================================WhereIf(false)
|
||||
@ -695,7 +678,7 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.WhereIf(false, "a.\"clicks\" > 100 and a.\"id\" = ?", new { id = 10 });
|
||||
query = select.WhereIf(false, "a.\"clicks\" > 100 and a.\"id\" = @id", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a", sql);
|
||||
query.ToList();
|
||||
@ -951,9 +934,9 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topicastable1\" a LEFT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\"", sql);
|
||||
|
||||
query = select.LeftJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = ?", new { bname = "xxx" }).AsTable(tableRule);
|
||||
query = select.LeftJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = @bname", new { bname = "xxx" }).AsTable(tableRule);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topicastable1\" a LEFT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = ?", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topicastable1\" a LEFT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = @bname", sql);
|
||||
}
|
||||
|
||||
public class TestInclude_OneToManyModel1
|
||||
@ -1048,6 +1031,40 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id)))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at0 = g.pgsql.Select<TestInclude_OneToManyModel2>()
|
||||
.IncludeMany(a => a.childs.Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at1 = g.pgsql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at2 = g.pgsql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TestInclude_OneToManyModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at00 = g.pgsql.Select<TestInclude_OneToManyModel2>()
|
||||
.IncludeMany(a => a.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at11 = g.pgsql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at22 = g.pgsql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TestInclude_OneToManyModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public class TestInclude_OneToManyModel11
|
||||
@ -1065,6 +1082,8 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string m2setting { get; set; }
|
||||
public string aaa { get; set; }
|
||||
public string bbb { get; set; }
|
||||
public List<TestInclude_OneToManyModel33> childs { get; set; }
|
||||
}
|
||||
public class TestInclude_OneToManyModel33
|
||||
@ -1079,7 +1098,7 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
public void Include_OneToMany2()
|
||||
{
|
||||
string setting = "x";
|
||||
var model2 = new TestInclude_OneToManyModel22 { m2setting = DateTime.Now.Second.ToString() };
|
||||
var model2 = new TestInclude_OneToManyModel22 { m2setting = DateTime.Now.Second.ToString(), aaa = "aaa" + DateTime.Now.Second, bbb = "bbb" + DateTime.Now.Second };
|
||||
model2.id = (int)g.pgsql.Insert(model2).ExecuteIdentity();
|
||||
|
||||
var model3s = new[]
|
||||
@ -1104,6 +1123,20 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at1 = g.pgsql.Select<TestInclude_OneToManyModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TestInclude_OneToManyModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
var at11 = g.pgsql.Select<TestInclude_OneToManyModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TestInclude_OneToManyModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1201,6 +1234,59 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
.IncludeMany(a => a.Songs.Take(1))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
// --- Select ---
|
||||
|
||||
var atags0 = g.pgsql.Select<Tag>()
|
||||
.Include(a => a.Parent)
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags1 = g.pgsql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags2 = g.pgsql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags3 = g.pgsql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags11 = g.pgsql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags22 = g.pgsql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags33 = g.pgsql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1305,6 +1391,61 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
// --- Select ---
|
||||
|
||||
new List<Song>(new[] { song1, song2, song3 }).IncludeMany(g.pgsql, a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }));
|
||||
|
||||
var asongs1 = g.pgsql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs1.Count);
|
||||
Assert.Equal(2, songs1[0].Tags.Count);
|
||||
Assert.Equal(1, songs1[1].Tags.Count);
|
||||
Assert.Equal(3, songs1[2].Tags.Count);
|
||||
|
||||
var asongs2 = g.pgsql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs2.Count);
|
||||
Assert.Equal(2, songs2[0].Tags.Count);
|
||||
Assert.Equal(1, songs2[1].Tags.Count);
|
||||
Assert.Equal(3, songs2[2].Tags.Count);
|
||||
|
||||
var atags3 = g.pgsql.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
|
||||
var asongs11 = g.pgsql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs11.Count);
|
||||
Assert.Equal(1, songs11[0].Tags.Count);
|
||||
Assert.Equal(1, songs11[1].Tags.Count);
|
||||
Assert.Equal(1, songs11[2].Tags.Count);
|
||||
|
||||
var asongs22 = g.pgsql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs22.Count);
|
||||
Assert.Equal(1, songs22[0].Tags.Count);
|
||||
Assert.Equal(1, songs22[1].Tags.Count);
|
||||
Assert.Equal(1, songs22[2].Tags.Count);
|
||||
|
||||
var atags33 = g.pgsql.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
public class ToDel1Pk
|
||||
|
@ -6,7 +6,6 @@ using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.SqlServer
|
||||
{
|
||||
[Collection("SqlServerCollection")]
|
||||
public class SqlServerSelectTest
|
||||
{
|
||||
ISelect<Topic> select => g.sqlserver.Select<Topic>();
|
||||
@ -141,7 +140,6 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
[Fact]
|
||||
public void ToList()
|
||||
{
|
||||
|
||||
var testDto1 = select.Limit(10).ToList(a => new TestDto { id = a.Id, name = a.Title });
|
||||
var testDto2 = select.Limit(10).ToList(a => new TestDto());
|
||||
var testDto3 = select.Limit(10).ToList(a => new TestDto { });
|
||||
@ -303,11 +301,6 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a LEFT JOIN TestTypeInfo b on b.Guid = a.TypeGuid", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.LeftJoin("TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = ?", new { bname = "xxx" });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a LEFT JOIN TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = ?", sql);
|
||||
query.ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void InnerJoin()
|
||||
@ -372,12 +365,6 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a INNER JOIN TestTypeInfo b on b.Guid = a.TypeGuid", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.InnerJoin("TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = ?", new { bname = "xxx" });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a INNER JOIN TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = ?", sql);
|
||||
query.ToList();
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void RightJoin()
|
||||
@ -442,12 +429,6 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a RIGHT JOIN TestTypeInfo b on b.Guid = a.TypeGuid", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.RightJoin("TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = ?", new { bname = "xxx" });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a RIGHT JOIN TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = ?", sql);
|
||||
query.ToList();
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void Where()
|
||||
@ -512,12 +493,6 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
sql = query2.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a, [TestTypeInfo] b, [TestTypeParentInfo] c WHERE (a.[Id] = 10 AND c.[Name] = N'xxx') AND (b.[ParentId] = 20)", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.Where("a.clicks > 100 and a.id = ?", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a WHERE (a.clicks > 100 and a.id = ?)", sql);
|
||||
query.ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void WhereIf()
|
||||
@ -561,12 +536,6 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a, [TestTypeInfo] b, [TestTypeParentInfo] c WHERE (a.[Id] = 10 AND c.[Name] = N'xxx') AND (b.[ParentId] = 20)", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.WhereIf(true, "a.clicks > 100 and a.id = ?", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a WHERE (a.clicks > 100 and a.id = ?)", sql);
|
||||
query.ToList();
|
||||
|
||||
// ==========================================WhereIf(false)
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a.Type<70><65>a.Type.Parent <20><><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -607,12 +576,6 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
sql = query2.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a, [TestTypeInfo] b, [TestTypeParentInfo] c", sql);
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.WhereIf(false, "a.clicks > 100 and a.id = ?", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a", sql);
|
||||
query.ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void WhereExists()
|
||||
@ -962,6 +925,40 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id)))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at0 = g.sqlserver.Select<TestInclude_OneToManyModel2>()
|
||||
.IncludeMany(a => a.childs.Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at1 = g.sqlserver.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at2 = g.sqlserver.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TestInclude_OneToManyModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at00 = g.sqlserver.Select<TestInclude_OneToManyModel2>()
|
||||
.IncludeMany(a => a.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at11 = g.sqlserver.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at22 = g.sqlserver.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TestInclude_OneToManyModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public class TestInclude_OneToManyModel11
|
||||
@ -979,6 +976,8 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string m2setting { get; set; }
|
||||
public string aaa { get; set; }
|
||||
public string bbb { get; set; }
|
||||
public List<TestInclude_OneToManyModel33> childs { get; set; }
|
||||
}
|
||||
public class TestInclude_OneToManyModel33
|
||||
@ -993,7 +992,7 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
public void Include_OneToMany2()
|
||||
{
|
||||
string setting = "x";
|
||||
var model2 = new TestInclude_OneToManyModel22 { m2setting = DateTime.Now.Second.ToString() };
|
||||
var model2 = new TestInclude_OneToManyModel22 { m2setting = DateTime.Now.Second.ToString(), aaa = "aaa" + DateTime.Now.Second, bbb = "bbb" + DateTime.Now.Second };
|
||||
model2.id = (int)g.sqlserver.Insert(model2).ExecuteIdentity();
|
||||
|
||||
var model3s = new[]
|
||||
@ -1018,6 +1017,20 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at1 = g.sqlserver.Select<TestInclude_OneToManyModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TestInclude_OneToManyModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
var at11 = g.sqlserver.Select<TestInclude_OneToManyModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TestInclude_OneToManyModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1115,6 +1128,59 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
.IncludeMany(a => a.Songs.Take(1))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
// --- Select ---
|
||||
|
||||
var atags0 = g.sqlserver.Select<Tag>()
|
||||
.Include(a => a.Parent)
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags1 = g.sqlserver.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags2 = g.sqlserver.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags3 = g.sqlserver.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags11 = g.sqlserver.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags22 = g.sqlserver.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags33 = g.sqlserver.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1219,6 +1285,61 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
// --- Select ---
|
||||
|
||||
new List<Song>(new[] { song1, song2, song3 }).IncludeMany(g.sqlserver, a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }));
|
||||
|
||||
var asongs1 = g.sqlserver.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs1.Count);
|
||||
Assert.Equal(2, songs1[0].Tags.Count);
|
||||
Assert.Equal(1, songs1[1].Tags.Count);
|
||||
Assert.Equal(3, songs1[2].Tags.Count);
|
||||
|
||||
var asongs2 = g.sqlserver.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs2.Count);
|
||||
Assert.Equal(2, songs2[0].Tags.Count);
|
||||
Assert.Equal(1, songs2[1].Tags.Count);
|
||||
Assert.Equal(3, songs2[2].Tags.Count);
|
||||
|
||||
var atags3 = g.sqlserver.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
|
||||
var asongs11 = g.sqlserver.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs11.Count);
|
||||
Assert.Equal(1, songs11[0].Tags.Count);
|
||||
Assert.Equal(1, songs11[1].Tags.Count);
|
||||
Assert.Equal(1, songs11[2].Tags.Count);
|
||||
|
||||
var asongs22 = g.sqlserver.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs22.Count);
|
||||
Assert.Equal(1, songs22[0].Tags.Count);
|
||||
Assert.Equal(1, songs22[1].Tags.Count);
|
||||
Assert.Equal(1, songs22[2].Tags.Count);
|
||||
|
||||
var atags33 = g.sqlserver.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
public class ToDel1Pk
|
||||
|
@ -1090,6 +1090,40 @@ namespace FreeSql.Tests.MySql
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id)))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at0 = g.mysql.Select<TestInclude_OneToManyModel2>()
|
||||
.IncludeMany(a => a.childs.Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at1 = g.mysql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at2 = g.mysql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TestInclude_OneToManyModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at00 = g.mysql.Select<TestInclude_OneToManyModel2>()
|
||||
.IncludeMany(a => a.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at11 = g.mysql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at22 = g.mysql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TestInclude_OneToManyModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public class TestInclude_OneToManyModel11
|
||||
@ -1107,6 +1141,8 @@ namespace FreeSql.Tests.MySql
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string m2setting { get; set; }
|
||||
public string aaa { get; set; }
|
||||
public string bbb { get; set; }
|
||||
public List<TestInclude_OneToManyModel33> childs { get; set; }
|
||||
}
|
||||
public class TestInclude_OneToManyModel33
|
||||
@ -1121,7 +1157,7 @@ namespace FreeSql.Tests.MySql
|
||||
public void Include_OneToMany2()
|
||||
{
|
||||
string setting = "x";
|
||||
var model2 = new TestInclude_OneToManyModel22 { m2setting = DateTime.Now.Second.ToString() };
|
||||
var model2 = new TestInclude_OneToManyModel22 { m2setting = DateTime.Now.Second.ToString(), aaa = "aaa" + DateTime.Now.Second, bbb = "bbb" + DateTime.Now.Second };
|
||||
model2.id = (int)g.mysql.Insert(model2).ExecuteIdentity();
|
||||
|
||||
var model3s = new[]
|
||||
@ -1146,6 +1182,20 @@ namespace FreeSql.Tests.MySql
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at1 = g.mysql.Select<TestInclude_OneToManyModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TestInclude_OneToManyModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
var at11 = g.mysql.Select<TestInclude_OneToManyModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TestInclude_OneToManyModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1243,6 +1293,59 @@ namespace FreeSql.Tests.MySql
|
||||
.IncludeMany(a => a.Songs.Take(1))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
// --- Select ---
|
||||
|
||||
var atags0 = g.mysql.Select<Tag>()
|
||||
.Include(a => a.Parent)
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags1 = g.mysql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags2 = g.mysql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags3 = g.mysql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags11 = g.mysql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags22 = g.mysql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags33 = g.mysql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1347,6 +1450,61 @@ namespace FreeSql.Tests.MySql
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
// --- Select ---
|
||||
|
||||
new List<Song>(new[] { song1, song2, song3 }).IncludeMany(g.mysql, a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }));
|
||||
|
||||
var asongs1 = g.mysql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs1.Count);
|
||||
Assert.Equal(2, songs1[0].Tags.Count);
|
||||
Assert.Equal(1, songs1[1].Tags.Count);
|
||||
Assert.Equal(3, songs1[2].Tags.Count);
|
||||
|
||||
var asongs2 = g.mysql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs2.Count);
|
||||
Assert.Equal(2, songs2[0].Tags.Count);
|
||||
Assert.Equal(1, songs2[1].Tags.Count);
|
||||
Assert.Equal(3, songs2[2].Tags.Count);
|
||||
|
||||
var atags3 = g.mysql.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
|
||||
var asongs11 = g.mysql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs11.Count);
|
||||
Assert.Equal(1, songs11[0].Tags.Count);
|
||||
Assert.Equal(1, songs11[1].Tags.Count);
|
||||
Assert.Equal(1, songs11[2].Tags.Count);
|
||||
|
||||
var asongs22 = g.mysql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs22.Count);
|
||||
Assert.Equal(1, songs22[0].Tags.Count);
|
||||
Assert.Equal(1, songs22[1].Tags.Count);
|
||||
Assert.Equal(1, songs22[2].Tags.Count);
|
||||
|
||||
var atags33 = g.mysql.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
public class ToDel1Pk
|
||||
|
@ -975,6 +975,40 @@ namespace FreeSql.Tests.Oracle
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id)))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at0 = g.oracle.Select<TiOtmModel2>()
|
||||
.IncludeMany(a => a.childs.Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TiOtmModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at1 = g.oracle.Select<TiOtmModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TiOtmModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at2 = g.oracle.Select<TiOtmModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TiOtmModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TiOtmModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at00 = g.oracle.Select<TiOtmModel2>()
|
||||
.IncludeMany(a => a.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TiOtmModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at11 = g.oracle.Select<TiOtmModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TiOtmModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at22 = g.oracle.Select<TiOtmModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TiOtmModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TiOtmModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public class TiOtmModel11
|
||||
@ -992,6 +1026,8 @@ namespace FreeSql.Tests.Oracle
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string m2setting { get; set; }
|
||||
public string aaa { get; set; }
|
||||
public string bbb { get; set; }
|
||||
public List<TiOtmModel33> childs { get; set; }
|
||||
}
|
||||
public class TiOtmModel33
|
||||
@ -1006,7 +1042,7 @@ namespace FreeSql.Tests.Oracle
|
||||
public void Include_OneToMany2()
|
||||
{
|
||||
string setting = "x";
|
||||
var model2 = new TiOtmModel22 { m2setting = DateTime.Now.Second.ToString() };
|
||||
var model2 = new TiOtmModel22 { m2setting = DateTime.Now.Second.ToString(), aaa = "aaa" + DateTime.Now.Second, bbb = "bbb" + DateTime.Now.Second };
|
||||
model2.id = (int)g.oracle.Insert(model2).ExecuteIdentity();
|
||||
|
||||
var model3s = new[]
|
||||
@ -1031,6 +1067,20 @@ namespace FreeSql.Tests.Oracle
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at1 = g.oracle.Select<TiOtmModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TiOtmModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
var at11 = g.oracle.Select<TiOtmModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TiOtmModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1128,6 +1178,59 @@ namespace FreeSql.Tests.Oracle
|
||||
.IncludeMany(a => a.Songs.Take(1))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
// --- Select ---
|
||||
|
||||
var atags0 = g.oracle.Select<Tag>()
|
||||
.Include(a => a.Parent)
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags1 = g.oracle.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags2 = g.oracle.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags3 = g.oracle.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags11 = g.oracle.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags22 = g.oracle.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags33 = g.oracle.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1232,6 +1335,61 @@ namespace FreeSql.Tests.Oracle
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
// --- Select ---
|
||||
|
||||
new List<Song>(new[] { song1, song2, song3 }).IncludeMany(g.oracle, a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }));
|
||||
|
||||
var asongs1 = g.oracle.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs1.Count);
|
||||
Assert.Equal(2, songs1[0].Tags.Count);
|
||||
Assert.Equal(1, songs1[1].Tags.Count);
|
||||
Assert.Equal(3, songs1[2].Tags.Count);
|
||||
|
||||
var asongs2 = g.oracle.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs2.Count);
|
||||
Assert.Equal(2, songs2[0].Tags.Count);
|
||||
Assert.Equal(1, songs2[1].Tags.Count);
|
||||
Assert.Equal(3, songs2[2].Tags.Count);
|
||||
|
||||
var atags3 = g.oracle.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
|
||||
var asongs11 = g.oracle.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs11.Count);
|
||||
Assert.Equal(1, songs11[0].Tags.Count);
|
||||
Assert.Equal(1, songs11[1].Tags.Count);
|
||||
Assert.Equal(1, songs11[2].Tags.Count);
|
||||
|
||||
var asongs22 = g.oracle.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs22.Count);
|
||||
Assert.Equal(1, songs22[0].Tags.Count);
|
||||
Assert.Equal(1, songs22[1].Tags.Count);
|
||||
Assert.Equal(1, songs22[2].Tags.Count);
|
||||
|
||||
var atags33 = g.oracle.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
public class ToDel1Pk
|
||||
|
@ -1048,6 +1048,40 @@ namespace FreeSql.Tests.PostgreSQL
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id)))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at0 = g.pgsql.Select<TestInclude_OneToManyModel2>()
|
||||
.IncludeMany(a => a.childs.Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at1 = g.pgsql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at2 = g.pgsql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TestInclude_OneToManyModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at00 = g.pgsql.Select<TestInclude_OneToManyModel2>()
|
||||
.IncludeMany(a => a.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at11 = g.pgsql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at22 = g.pgsql.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TestInclude_OneToManyModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public class TestInclude_OneToManyModel11
|
||||
@ -1065,6 +1099,8 @@ namespace FreeSql.Tests.PostgreSQL
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string m2setting { get; set; }
|
||||
public string aaa { get; set; }
|
||||
public string bbb { get; set; }
|
||||
public List<TestInclude_OneToManyModel33> childs { get; set; }
|
||||
}
|
||||
public class TestInclude_OneToManyModel33
|
||||
@ -1079,7 +1115,7 @@ namespace FreeSql.Tests.PostgreSQL
|
||||
public void Include_OneToMany2()
|
||||
{
|
||||
string setting = "x";
|
||||
var model2 = new TestInclude_OneToManyModel22 { m2setting = DateTime.Now.Second.ToString() };
|
||||
var model2 = new TestInclude_OneToManyModel22 { m2setting = DateTime.Now.Second.ToString(), aaa = "aaa" + DateTime.Now.Second, bbb = "bbb" + DateTime.Now.Second };
|
||||
model2.id = (int)g.pgsql.Insert(model2).ExecuteIdentity();
|
||||
|
||||
var model3s = new[]
|
||||
@ -1104,6 +1140,20 @@ namespace FreeSql.Tests.PostgreSQL
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at1 = g.pgsql.Select<TestInclude_OneToManyModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TestInclude_OneToManyModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
var at11 = g.pgsql.Select<TestInclude_OneToManyModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TestInclude_OneToManyModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1201,6 +1251,59 @@ namespace FreeSql.Tests.PostgreSQL
|
||||
.IncludeMany(a => a.Songs.Take(1))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
// --- Select ---
|
||||
|
||||
var atags0 = g.pgsql.Select<Tag>()
|
||||
.Include(a => a.Parent)
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags1 = g.pgsql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags2 = g.pgsql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags3 = g.pgsql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags11 = g.pgsql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags22 = g.pgsql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags33 = g.pgsql.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1305,6 +1408,61 @@ namespace FreeSql.Tests.PostgreSQL
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
// --- Select ---
|
||||
|
||||
new List<Song>(new[] { song1, song2, song3 }).IncludeMany(g.pgsql, a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }));
|
||||
|
||||
var asongs1 = g.pgsql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs1.Count);
|
||||
Assert.Equal(2, songs1[0].Tags.Count);
|
||||
Assert.Equal(1, songs1[1].Tags.Count);
|
||||
Assert.Equal(3, songs1[2].Tags.Count);
|
||||
|
||||
var asongs2 = g.pgsql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs2.Count);
|
||||
Assert.Equal(2, songs2[0].Tags.Count);
|
||||
Assert.Equal(1, songs2[1].Tags.Count);
|
||||
Assert.Equal(3, songs2[2].Tags.Count);
|
||||
|
||||
var atags3 = g.pgsql.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
|
||||
var asongs11 = g.pgsql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs11.Count);
|
||||
Assert.Equal(1, songs11[0].Tags.Count);
|
||||
Assert.Equal(1, songs11[1].Tags.Count);
|
||||
Assert.Equal(1, songs11[2].Tags.Count);
|
||||
|
||||
var asongs22 = g.pgsql.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs22.Count);
|
||||
Assert.Equal(1, songs22[0].Tags.Count);
|
||||
Assert.Equal(1, songs22[1].Tags.Count);
|
||||
Assert.Equal(1, songs22[2].Tags.Count);
|
||||
|
||||
var atags33 = g.pgsql.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
public class ToDel1Pk
|
||||
|
@ -970,6 +970,40 @@ namespace FreeSql.Tests.SqlServer
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id)))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at0 = g.sqlserver.Select<TestInclude_OneToManyModel2>()
|
||||
.IncludeMany(a => a.childs.Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at1 = g.sqlserver.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at2 = g.sqlserver.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TestInclude_OneToManyModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at00 = g.sqlserver.Select<TestInclude_OneToManyModel2>()
|
||||
.IncludeMany(a => a.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at11 = g.sqlserver.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at22 = g.sqlserver.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TestInclude_OneToManyModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public class TestInclude_OneToManyModel11
|
||||
@ -987,6 +1021,8 @@ namespace FreeSql.Tests.SqlServer
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string m2setting { get; set; }
|
||||
public string aaa { get; set; }
|
||||
public string bbb { get; set; }
|
||||
public List<TestInclude_OneToManyModel33> childs { get; set; }
|
||||
}
|
||||
public class TestInclude_OneToManyModel33
|
||||
@ -1001,7 +1037,7 @@ namespace FreeSql.Tests.SqlServer
|
||||
public void Include_OneToMany2()
|
||||
{
|
||||
string setting = "x";
|
||||
var model2 = new TestInclude_OneToManyModel22 { m2setting = DateTime.Now.Second.ToString() };
|
||||
var model2 = new TestInclude_OneToManyModel22 { m2setting = DateTime.Now.Second.ToString(), aaa = "aaa" + DateTime.Now.Second, bbb = "bbb" + DateTime.Now.Second };
|
||||
model2.id = (int)_sqlserverFixture.SqlServer.Insert(model2).ExecuteIdentity();
|
||||
|
||||
var model3s = new[]
|
||||
@ -1026,6 +1062,20 @@ namespace FreeSql.Tests.SqlServer
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at1 = g.sqlserver.Select<TestInclude_OneToManyModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TestInclude_OneToManyModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
var at11 = g.sqlserver.Select<TestInclude_OneToManyModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TestInclude_OneToManyModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1123,6 +1173,59 @@ namespace FreeSql.Tests.SqlServer
|
||||
.IncludeMany(a => a.Songs.Take(1))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
// --- Select ---
|
||||
|
||||
var atags0 = g.sqlserver.Select<Tag>()
|
||||
.Include(a => a.Parent)
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags1 = g.sqlserver.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags2 = g.sqlserver.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags3 = g.sqlserver.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags11 = g.sqlserver.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags22 = g.sqlserver.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags33 = g.sqlserver.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1227,6 +1330,61 @@ namespace FreeSql.Tests.SqlServer
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
// --- Select ---
|
||||
|
||||
new List<Song>(new[] { song1, song2, song3 }).IncludeMany(g.sqlserver, a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }));
|
||||
|
||||
var asongs1 = g.sqlserver.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs1.Count);
|
||||
Assert.Equal(2, songs1[0].Tags.Count);
|
||||
Assert.Equal(1, songs1[1].Tags.Count);
|
||||
Assert.Equal(3, songs1[2].Tags.Count);
|
||||
|
||||
var asongs2 = g.sqlserver.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs2.Count);
|
||||
Assert.Equal(2, songs2[0].Tags.Count);
|
||||
Assert.Equal(1, songs2[1].Tags.Count);
|
||||
Assert.Equal(3, songs2[2].Tags.Count);
|
||||
|
||||
var atags3 = g.sqlserver.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
|
||||
var asongs11 = g.sqlserver.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs11.Count);
|
||||
Assert.Equal(1, songs11[0].Tags.Count);
|
||||
Assert.Equal(1, songs11[1].Tags.Count);
|
||||
Assert.Equal(1, songs11[2].Tags.Count);
|
||||
|
||||
var asongs22 = g.sqlserver.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs22.Count);
|
||||
Assert.Equal(1, songs22[0].Tags.Count);
|
||||
Assert.Equal(1, songs22[1].Tags.Count);
|
||||
Assert.Equal(1, songs22[2].Tags.Count);
|
||||
|
||||
var atags33 = g.sqlserver.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
public class ToDel1Pk
|
||||
|
@ -951,6 +951,40 @@ namespace FreeSql.Tests.Sqlite
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id)))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at0 = g.sqlite.Select<TestInclude_OneToManyModel2>()
|
||||
.IncludeMany(a => a.childs.Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at1 = g.sqlite.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at2 = g.sqlite.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TestInclude_OneToManyModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at00 = g.sqlite.Select<TestInclude_OneToManyModel2>()
|
||||
.IncludeMany(a => a.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.model2id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at11 = g.sqlite.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
|
||||
var at22 = g.sqlite.Select<TestInclude_OneToManyModel1>()
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }),
|
||||
then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TestInclude_OneToManyModel4 { id = m4.id })))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public class TestInclude_OneToManyModel11
|
||||
@ -968,6 +1002,8 @@ namespace FreeSql.Tests.Sqlite
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string m2setting { get; set; }
|
||||
public string aaa { get; set; }
|
||||
public string bbb { get; set; }
|
||||
public List<TestInclude_OneToManyModel33> childs { get; set; }
|
||||
}
|
||||
public class TestInclude_OneToManyModel33
|
||||
@ -982,7 +1018,7 @@ namespace FreeSql.Tests.Sqlite
|
||||
public void Include_OneToMany2()
|
||||
{
|
||||
string setting = "x";
|
||||
var model2 = new TestInclude_OneToManyModel22 { m2setting = DateTime.Now.Second.ToString() };
|
||||
var model2 = new TestInclude_OneToManyModel22 { m2setting = DateTime.Now.Second.ToString(), aaa = "aaa" + DateTime.Now.Second, bbb = "bbb" + DateTime.Now.Second };
|
||||
model2.id = (int)g.sqlite.Insert(model2).ExecuteIdentity();
|
||||
|
||||
var model3s = new[]
|
||||
@ -1007,6 +1043,20 @@ namespace FreeSql.Tests.Sqlite
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
//---- Select ----
|
||||
|
||||
var at1 = g.sqlite.Select<TestInclude_OneToManyModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TestInclude_OneToManyModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
|
||||
var at11 = g.sqlite.Select<TestInclude_OneToManyModel11>()
|
||||
.LeftJoin(a => a.model2id == a.model2.id)
|
||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TestInclude_OneToManyModel33 { title = m3.title }))
|
||||
.Where(a => a.id <= model1.id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1104,6 +1154,59 @@ namespace FreeSql.Tests.Sqlite
|
||||
.IncludeMany(a => a.Songs.Take(1))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
// --- Select ---
|
||||
|
||||
var atags0 = g.sqlite.Select<Tag>()
|
||||
.Include(a => a.Parent)
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags1 = g.sqlite.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags2 = g.sqlite.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags3 = g.sqlite.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags11 = g.sqlite.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags22 = g.sqlite.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
|
||||
var atags33 = g.sqlite.Select<Tag>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name })))
|
||||
.Include(a => a.Parent)
|
||||
.IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Id == tag1.Id || a.Id == tag2.Id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -1209,6 +1312,61 @@ namespace FreeSql.Tests.Sqlite
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
// --- Select ---
|
||||
|
||||
new List<Song>(new[] { song1, song2, song3 }).IncludeMany(g.sqlite, a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }));
|
||||
|
||||
var asongs1 = g.sqlite.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs1.Count);
|
||||
Assert.Equal(2, songs1[0].Tags.Count);
|
||||
Assert.Equal(1, songs1[1].Tags.Count);
|
||||
Assert.Equal(3, songs1[2].Tags.Count);
|
||||
|
||||
var asongs2 = g.sqlite.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs2.Count);
|
||||
Assert.Equal(2, songs2[0].Tags.Count);
|
||||
Assert.Equal(1, songs2[1].Tags.Count);
|
||||
Assert.Equal(3, songs2[2].Tags.Count);
|
||||
|
||||
var atags3 = g.sqlite.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
|
||||
|
||||
var asongs11 = g.sqlite.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs11.Count);
|
||||
Assert.Equal(1, songs11[0].Tags.Count);
|
||||
Assert.Equal(1, songs11[1].Tags.Count);
|
||||
Assert.Equal(1, songs11[2].Tags.Count);
|
||||
|
||||
var asongs22 = g.sqlite.Select<Song>()
|
||||
.IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }),
|
||||
then => then.IncludeMany(t => t.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })))
|
||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||
.ToList();
|
||||
Assert.Equal(3, songs22.Count);
|
||||
Assert.Equal(1, songs22[0].Tags.Count);
|
||||
Assert.Equal(1, songs22[1].Tags.Count);
|
||||
Assert.Equal(1, songs22[2].Tags.Count);
|
||||
|
||||
var atags33 = g.sqlite.Select<Song_tag>()
|
||||
.Include(a => a.Tag.Parent)
|
||||
.IncludeMany(a => a.Tag.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))
|
||||
.Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id)
|
||||
.ToList(true);
|
||||
}
|
||||
|
||||
public class ToDel1Pk
|
||||
|
@ -192,11 +192,12 @@ public static partial class FreeSqlGlobalExtensions
|
||||
/// 示例:new List<Song>(new[] { song1, song2, song3 }).IncludeMany(g.sqlite, a => a.Tags);<para></para>
|
||||
/// 文档:https://github.com/2881099/FreeSql/wiki/%e8%b4%aa%e5%a9%aa%e5%8a%a0%e8%bd%bd#%E5%AF%BC%E8%88%AA%E5%B1%9E%E6%80%A7-onetomanymanytomany
|
||||
/// </summary>
|
||||
/// <typeparam name="T1"></typeparam>
|
||||
/// <typeparam name="TNavigate"></typeparam>
|
||||
/// <param name="list"></param>
|
||||
/// <param name="orm"></param>
|
||||
/// <param name="navigateSelector">选择一个集合的导航属性,也可通过 .Where 设置临时的关系映射,还可以 .Take(5) 每个子集合只取5条</param>
|
||||
/// <param name="navigateSelector">选择一个集合的导航属性,如: .IncludeMany(a => a.Tags)<para></para>
|
||||
/// 可以 .Where 设置临时的关系映射,如: .IncludeMany(a => a.Tags.Where(tag => tag.TypeId == a.Id))<para></para>
|
||||
/// 可以 .Take(5) 每个子集合只取5条,如: .IncludeMany(a => a.Tags.Take(5))<para></para>
|
||||
/// 可以 .Select 设置只查询部分字段,如: (a => new TNavigate { Title = a.Title })
|
||||
/// </param>
|
||||
/// <param name="then">即能 ThenInclude,还可以二次过滤(这个 EFCore 做不到?)</param>
|
||||
/// <returns></returns>
|
||||
public static List<T1> IncludeMany<T1, TNavigate>(this List<T1> list, IFreeSql orm, Expression<Func<T1, IEnumerable<TNavigate>>> navigateSelector, Action<ISelect<TNavigate>> then = null) where T1 : class where TNavigate : class
|
||||
|
@ -1490,7 +1490,11 @@
|
||||
文档:https://github.com/2881099/FreeSql/wiki/%e8%b4%aa%e5%a9%aa%e5%8a%a0%e8%bd%bd#%E5%AF%BC%E8%88%AA%E5%B1%9E%E6%80%A7-onetomanymanytomany
|
||||
</summary>
|
||||
<typeparam name="TNavigate"></typeparam>
|
||||
<param name="navigateSelector">选择一个集合的导航属性,也可通过 .Where 设置临时的关系映射,还可以 .Take(5) 每个子集合只取5条</param>
|
||||
<param name="navigateSelector">选择一个集合的导航属性,如: .IncludeMany(a => a.Tags)<para></para>
|
||||
可以 .Where 设置临时的关系映射,如: .IncludeMany(a => a.Tags.Where(tag => tag.TypeId == a.Id))<para></para>
|
||||
可以 .Take(5) 每个子集合只取5条,如: .IncludeMany(a => a.Tags.Take(5))<para></para>
|
||||
可以 .Select 设置只查询部分字段,如: (a => new TNavigate { Title = a.Title })
|
||||
</param>
|
||||
<param name="then">即能 ThenInclude,还可以二次过滤(这个 EFCore 做不到?)</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
@ -1996,137 +2000,6 @@
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteReaderAsync(System.Func{System.Data.Common.DbDataReader,System.Threading.Tasks.Task},System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
查询,若使用读写分离,查询【从库】条件cmdText.StartsWith("SELECT "),否则查询【主库】
|
||||
</summary>
|
||||
<param name="readerHander"></param>
|
||||
<param name="cmdType"></param>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteReaderAsync(System.Func{System.Data.Common.DbDataReader,System.Threading.Tasks.Task},System.String,System.Object)">
|
||||
<summary>
|
||||
查询,ExecuteReaderAsync(dr => {}, "select * from user where age > @age", new { age = 25 })
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteArrayAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
查询
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteArrayAsync(System.String,System.Object)">
|
||||
<summary>
|
||||
查询,ExecuteArrayAsync("select * from user where age > @age", new { age = 25 })
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteDataSetAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
查询
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteDataSetAsync(System.String,System.Object)">
|
||||
<summary>
|
||||
查询,ExecuteDataSetAsync("select * from user where age > @age; select 2", new { age = 25 })
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteDataTableAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
查询
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteDataTableAsync(System.String,System.Object)">
|
||||
<summary>
|
||||
查询,ExecuteDataTableAsync("select * from user where age > @age", new { age = 25 })
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteNonQueryAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
在【主库】执行
|
||||
</summary>
|
||||
<param name="cmdType"></param>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteNonQueryAsync(System.String,System.Object)">
|
||||
<summary>
|
||||
在【主库】执行,ExecuteNonQueryAsync("delete from user where age > @age", new { age = 25 })
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteScalarAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
在【主库】执行
|
||||
</summary>
|
||||
<param name="cmdType"></param>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteScalarAsync(System.String,System.Object)">
|
||||
<summary>
|
||||
在【主库】执行,ExecuteScalarAsync("select 1 from user where age > @age", new { age = 25 })
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.QueryAsync``1(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
执行SQL返回对象集合,QueryAsync<User>("select * from user where age > @age", new SqlParameter { ParameterName = "age", Value = 25 })
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<param name="cmdType"></param>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.QueryAsync``1(System.String,System.Object)">
|
||||
<summary>
|
||||
执行SQL返回对象集合,QueryAsync<User>("select * from user where age > @age", new { age = 25 })
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.QueryAsync``2(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
执行SQL返回对象集合,Query<User>("select * from user where age > @age; select * from address", new SqlParameter { ParameterName = "age", Value = 25 })
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="cmdType"></param>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.QueryAsync``2(System.String,System.Object)">
|
||||
<summary>
|
||||
执行SQL返回对象集合,Query<User>("select * from user where age > @age; select * from address", new { age = 25 })
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:FreeSql.IAop.ParseExpression">
|
||||
<summary>
|
||||
可自定义解析表达式
|
||||
@ -2657,11 +2530,12 @@
|
||||
示例:new List<Song>(new[] { song1, song2, song3 }).IncludeMany(g.sqlite, a => a.Tags);<para></para>
|
||||
文档:https://github.com/2881099/FreeSql/wiki/%e8%b4%aa%e5%a9%aa%e5%8a%a0%e8%bd%bd#%E5%AF%BC%E8%88%AA%E5%B1%9E%E6%80%A7-onetomanymanytomany
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<typeparam name="TNavigate"></typeparam>
|
||||
<param name="list"></param>
|
||||
<param name="orm"></param>
|
||||
<param name="navigateSelector">选择一个集合的导航属性,也可通过 .Where 设置临时的关系映射,还可以 .Take(5) 每个子集合只取5条</param>
|
||||
<param name="navigateSelector">选择一个集合的导航属性,如: .IncludeMany(a => a.Tags)<para></para>
|
||||
可以 .Where 设置临时的关系映射,如: .IncludeMany(a => a.Tags.Where(tag => tag.TypeId == a.Id))<para></para>
|
||||
可以 .Take(5) 每个子集合只取5条,如: .IncludeMany(a => a.Tags.Take(5))<para></para>
|
||||
可以 .Select 设置只查询部分字段,如: (a => new TNavigate { Title = a.Title })
|
||||
</param>
|
||||
<param name="then">即能 ThenInclude,还可以二次过滤(这个 EFCore 做不到?)</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
@ -2836,3 +2710,159 @@
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
</member>
|
||||
<member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Or``1(System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}},System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}})">
|
||||
<summary>
|
||||
使用 or 拼接两个 lambda 表达式
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Or``1(System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}},System.Boolean,System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}})">
|
||||
<summary>
|
||||
使用 or 拼接两个 lambda 表达式
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<param name="exp1"></param>
|
||||
<param name="condition">true 时生效</param>
|
||||
<param name="exp2"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Not``1(System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}},System.Boolean)">
|
||||
<summary>
|
||||
将 lambda 表达式取反
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<param name="exp"></param>
|
||||
<param name="condition">true 时生效</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeUtil.NewMongodbId">
|
||||
<summary>
|
||||
生成类似Mongodb的ObjectId有序、不重复Guid
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Insert``1">
|
||||
<summary>
|
||||
插入数据
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Insert``1(``0)">
|
||||
<summary>
|
||||
插入数据,传入实体
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="source"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Insert``1(``0[])">
|
||||
<summary>
|
||||
插入数据,传入实体数组
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="source"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Insert``1(System.Collections.Generic.List{``0})">
|
||||
<summary>
|
||||
插入数据,传入实体集合
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="source"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Insert``1(System.Collections.Generic.IEnumerable{``0})">
|
||||
<summary>
|
||||
插入数据,传入实体集合
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="source"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Update``1">
|
||||
<summary>
|
||||
修改数据
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Update``1(System.Object)">
|
||||
<summary>
|
||||
修改数据,传入动态对象如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Select``1">
|
||||
<summary>
|
||||
查询数据
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Select``1(System.Object)">
|
||||
<summary>
|
||||
查询数据,传入动态对象如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Delete``1">
|
||||
<summary>
|
||||
删除数据
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Delete``1(System.Object)">
|
||||
<summary>
|
||||
删除数据,传入动态对象如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Transaction(System.Action)">
|
||||
<summary>
|
||||
开启事务(不支持异步),60秒未执行完将自动提交
|
||||
</summary>
|
||||
<param name="handler">事务体 () => {}</param>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Transaction(System.Action,System.TimeSpan)">
|
||||
<summary>
|
||||
开启事务(不支持异步)
|
||||
</summary>
|
||||
<param name="handler">事务体 () => {}</param>
|
||||
<param name="timeout">超时,未执行完将自动提交</param>
|
||||
</member>
|
||||
<member name="P:IFreeSql.Ado">
|
||||
<summary>
|
||||
数据库访问对象
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IFreeSql.Aop">
|
||||
<summary>
|
||||
所有拦截方法都在这里
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IFreeSql.CodeFirst">
|
||||
<summary>
|
||||
CodeFirst 模式开发相关方法
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IFreeSql.DbFirst">
|
||||
<summary>
|
||||
DbFirst 模式开发相关方法
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IFreeSql.GlobalFilter">
|
||||
<summary>
|
||||
全局过滤设置,可默认附加为 Select/Update/Delete 条件
|
||||
</summary>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
@ -359,7 +359,11 @@ namespace FreeSql
|
||||
/// 文档:https://github.com/2881099/FreeSql/wiki/%e8%b4%aa%e5%a9%aa%e5%8a%a0%e8%bd%bd#%E5%AF%BC%E8%88%AA%E5%B1%9E%E6%80%A7-onetomanymanytomany
|
||||
/// </summary>
|
||||
/// <typeparam name="TNavigate"></typeparam>
|
||||
/// <param name="navigateSelector">选择一个集合的导航属性,也可通过 .Where 设置临时的关系映射,还可以 .Take(5) 每个子集合只取5条</param>
|
||||
/// <param name="navigateSelector">选择一个集合的导航属性,如: .IncludeMany(a => a.Tags)<para></para>
|
||||
/// 可以 .Where 设置临时的关系映射,如: .IncludeMany(a => a.Tags.Where(tag => tag.TypeId == a.Id))<para></para>
|
||||
/// 可以 .Take(5) 每个子集合只取5条,如: .IncludeMany(a => a.Tags.Take(5))<para></para>
|
||||
/// 可以 .Select 设置只查询部分字段,如: (a => new TNavigate { Title = a.Title })
|
||||
/// </param>
|
||||
/// <param name="then">即能 ThenInclude,还可以二次过滤(这个 EFCore 做不到?)</param>
|
||||
/// <returns></returns>
|
||||
ISelect<T1> IncludeMany<TNavigate>(Expression<Func<T1, IEnumerable<TNavigate>>> navigateSelector, Action<ISelect<TNavigate>> then = null) where TNavigate : class;
|
||||
|
@ -108,6 +108,8 @@ namespace FreeSql.Internal
|
||||
parent.Consturctor = initExp.NewExpression.Type.GetConstructors()[0];
|
||||
parent.ConsturctorType = ReadAnonymousTypeInfoConsturctorType.Properties;
|
||||
|
||||
if (initExp.NewExpression.Type != _tables.FirstOrDefault()?.Table.Type)
|
||||
{
|
||||
//dto 映射
|
||||
var dtoProps = initExp.NewExpression.Type.GetPropertiesDictIgnoreCase().Values;
|
||||
foreach (var dtoProp in dtoProps)
|
||||
@ -136,6 +138,7 @@ namespace FreeSql.Internal
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (initExp.Bindings?.Count > 0)
|
||||
{
|
||||
//指定 dto映射
|
||||
|
@ -462,9 +462,8 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
public T1 First() => this.ToOne();
|
||||
|
||||
protected List<TReturn> ToListMapReader<TReturn>((ReadAnonymousTypeInfo map, string field) af)
|
||||
internal List<TReturn> ToListMrPrivate<TReturn>(string sql, (ReadAnonymousTypeInfo map, string field) af, (string field, ReadAnonymousTypeInfo read, List<object> retlist)[] otherData)
|
||||
{
|
||||
var sql = this.ToSql(af.field);
|
||||
var type = typeof(TReturn);
|
||||
var dbParms = _params.ToArray();
|
||||
var before = new Aop.CurdBeforeEventArgs(_tables[0].Table.Type, _tables[0].Table, Aop.CurdType.Select, sql, dbParms);
|
||||
@ -477,6 +476,9 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
var index = -1;
|
||||
ret.Add((TReturn)_commonExpression.ReadAnonymous(af.map, dr, ref index, false));
|
||||
if (otherData != null)
|
||||
foreach (var other in otherData)
|
||||
other.retlist.Add(_commonExpression.ReadAnonymous(other.read, dr, ref index, false));
|
||||
}, CommandType.Text, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -489,9 +491,27 @@ namespace FreeSql.Internal.CommonProvider
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||
}
|
||||
if (typeof(TReturn) == typeof(T1))
|
||||
foreach (var include in _includeToList) include?.Invoke(ret);
|
||||
_trackToList?.Invoke(ret);
|
||||
return ret;
|
||||
}
|
||||
internal List<TReturn> ToListMapReaderPrivate<TReturn>((ReadAnonymousTypeInfo map, string field) af, (string field, ReadAnonymousTypeInfo read, List<object> retlist)[] otherData)
|
||||
{
|
||||
string sql = null;
|
||||
if (otherData?.Length > 0)
|
||||
{
|
||||
var sbField = new StringBuilder().Append(af.field);
|
||||
foreach (var other in otherData)
|
||||
sbField.Append(other.field);
|
||||
sql = this.ToSql(sbField.ToString());
|
||||
}
|
||||
else
|
||||
sql = this.ToSql(af.field);
|
||||
|
||||
return ToListMrPrivate<TReturn>(sql, af, otherData);
|
||||
}
|
||||
protected List<TReturn> ToListMapReader<TReturn>((ReadAnonymousTypeInfo map, string field) af) => ToListMapReaderPrivate<TReturn>(af, null);
|
||||
protected (ReadAnonymousTypeInfo map, string field) GetExpressionField(Expression newexp)
|
||||
{
|
||||
var map = new ReadAnonymousTypeInfo();
|
||||
@ -1163,9 +1183,8 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
public Task<T1> FirstAsync() => this.ToOneAsync();
|
||||
|
||||
async protected Task<List<TReturn>> ToListMapReaderAsync<TReturn>((ReadAnonymousTypeInfo map, string field) af)
|
||||
async internal Task<List<TReturn>> ToListMrPrivateAsync<TReturn>(string sql, (ReadAnonymousTypeInfo map, string field) af, (string field, ReadAnonymousTypeInfo read, List<object> retlist)[] otherData)
|
||||
{
|
||||
var sql = this.ToSql(af.field);
|
||||
var type = typeof(TReturn);
|
||||
var dbParms = _params.ToArray();
|
||||
var before = new Aop.CurdBeforeEventArgs(_tables[0].Table.Type, _tables[0].Table, Aop.CurdType.Select, sql, dbParms);
|
||||
@ -1178,6 +1197,9 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
var index = -1;
|
||||
ret.Add((TReturn)_commonExpression.ReadAnonymous(af.map, dr, ref index, false));
|
||||
if (otherData != null)
|
||||
foreach (var other in otherData)
|
||||
other.retlist.Add(_commonExpression.ReadAnonymous(other.read, dr, ref index, false));
|
||||
return Task.FromResult(false);
|
||||
}, CommandType.Text, sql, dbParms);
|
||||
}
|
||||
@ -1191,9 +1213,27 @@ namespace FreeSql.Internal.CommonProvider
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||
}
|
||||
if (typeof(TReturn) == typeof(T1))
|
||||
foreach (var include in _includeToList) include?.Invoke(ret);
|
||||
_trackToList?.Invoke(ret);
|
||||
return ret;
|
||||
}
|
||||
internal Task<List<TReturn>> ToListMapReaderPrivateAsync<TReturn>((ReadAnonymousTypeInfo map, string field) af, (string field, ReadAnonymousTypeInfo read, List<object> retlist)[] otherData)
|
||||
{
|
||||
string sql = null;
|
||||
if (otherData?.Length > 0)
|
||||
{
|
||||
var sbField = new StringBuilder().Append(af.field);
|
||||
foreach (var other in otherData)
|
||||
sbField.Append(other.field);
|
||||
sql = this.ToSql(sbField.ToString());
|
||||
}
|
||||
else
|
||||
sql = this.ToSql(af.field);
|
||||
|
||||
return ToListMrPrivateAsync<TReturn>(sql, af, otherData);
|
||||
}
|
||||
protected Task<List<TReturn>> ToListMapReaderAsync<TReturn>((ReadAnonymousTypeInfo map, string field) af) => ToListMapReaderPrivateAsync<TReturn>(af, null);
|
||||
|
||||
async protected Task<TMember> InternalAvgAsync<TMember>(Expression exp) => (await this.ToListAsync<TMember>($"avg({_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null)})")).FirstOrDefault();
|
||||
async protected Task<TMember> InternalMaxAsync<TMember>(Expression exp) => (await this.ToListAsync<TMember>($"max({_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null)})")).FirstOrDefault();
|
||||
|
@ -386,16 +386,23 @@ namespace FreeSql.Internal.CommonProvider
|
||||
if (expBody == null) return this;
|
||||
MethodCallExpression whereExp = null;
|
||||
int takeNumber = 0;
|
||||
Expression<Func<TNavigate, TNavigate>> selectExp = null;
|
||||
while (expBody.NodeType == ExpressionType.Call)
|
||||
{
|
||||
throwNavigateSelector = new Exception($"IncludeMany {nameof(navigateSelector)} 参数类型错误,表达式格式应该是 a.collections.Take(1).Where(c => c.aid == a.id)");
|
||||
throwNavigateSelector = new Exception($"IncludeMany {nameof(navigateSelector)} 参数类型错误,正确格式: a.collections.Take(1).Where(c => c.aid == a.id).Select(a => new TNavigate {{ }})");
|
||||
var callExp = (expBody as MethodCallExpression);
|
||||
switch (callExp.Method.Name)
|
||||
{
|
||||
case "Where":
|
||||
whereExp = callExp;
|
||||
break;
|
||||
case "Take": takeNumber = int.Parse((callExp.Arguments[1] as ConstantExpression)?.Value?.ToString() ?? "0"); break;
|
||||
case "Take":
|
||||
takeNumber = int.Parse(_commonExpression.ExpressionLambdaToSql(callExp.Arguments[1], new CommonExpression.ExpTSC { }));
|
||||
break;
|
||||
case "Select":
|
||||
selectExp = (callExp.Arguments[1] as Expression<Func<TNavigate, TNavigate>>);
|
||||
if (selectExp?.Parameters.Count != 1) throw new Exception($"IncludeMany {nameof(navigateSelector)} 参数错误,Select 只可以使用一个参数的方法,正确格式: .Select(t => new TNavigate {{ }})");
|
||||
break;
|
||||
default: throw throwNavigateSelector;
|
||||
}
|
||||
expBody = callExp.Object ?? callExp.Arguments.FirstOrDefault();
|
||||
@ -406,6 +413,9 @@ namespace FreeSql.Internal.CommonProvider
|
||||
var (membersParam, members) = GetExpressionStack(collMem.Expression);
|
||||
var tb = _commonUtils.GetTableByEntity(collMem.Expression.Type);
|
||||
if (tb == null) throw throwNavigateSelector;
|
||||
var collMemElementType = (collMem.Type.IsGenericType ? collMem.Type.GetGenericArguments().FirstOrDefault() : collMem.Type.GetElementType());
|
||||
if (typeof(TNavigate) != collMemElementType)
|
||||
throw new Exception($"IncludeMany {nameof(navigateSelector)} 参数错误,Select lambda参数返回值必须和 {collMemElementType} 类型一致");
|
||||
var tbNav = _commonUtils.GetTableByEntity(typeof(TNavigate));
|
||||
if (tbNav == null) throw new Exception($"类型 {typeof(TNavigate).FullName} 错误,不能使用 IncludeMany");
|
||||
|
||||
@ -588,6 +598,22 @@ namespace FreeSql.Internal.CommonProvider
|
||||
var oldWhere = subSelect._where.ToString();
|
||||
if (oldWhere.StartsWith(" AND ")) oldWhere = oldWhere.Remove(0, 5);
|
||||
|
||||
if (selectExp != null)
|
||||
{
|
||||
var tmpinitExp = selectExp.Body as MemberInitExpression;
|
||||
var newinitExpBindings = tmpinitExp.Bindings.ToList();
|
||||
foreach (var tbrefCol in tbref.RefColumns)
|
||||
{
|
||||
if (newinitExpBindings.Any(a => a.Member.Name == tbrefCol.CsName)) continue;
|
||||
var tmpMemberInfo = tbrefCol.Table.Properties[tbrefCol.CsName];
|
||||
newinitExpBindings.Add(Expression.Bind(tmpMemberInfo, Expression.MakeMemberAccess(selectExp.Parameters[0], tmpMemberInfo)));
|
||||
}
|
||||
Expression newinitExp = Expression.MemberInit(tmpinitExp.NewExpression, newinitExpBindings.ToList());
|
||||
var selectExpParam = subSelect._tables[0].Parameter ?? Expression.Parameter(typeof(TNavigate), subSelectT1Alias);
|
||||
newinitExp = new NewExpressionVisitor(selectExpParam, selectExp.Parameters[0]).Replace(newinitExp);
|
||||
selectExp = Expression.Lambda<Func<TNavigate, TNavigate>>(newinitExp, selectExpParam);
|
||||
}
|
||||
|
||||
switch (tbref.RefType)
|
||||
{
|
||||
case TableRefType.OneToMany:
|
||||
@ -616,19 +642,23 @@ namespace FreeSql.Internal.CommonProvider
|
||||
};
|
||||
if (takeNumber > 0)
|
||||
{
|
||||
var af = subSelect.GetAllFieldExpressionTreeLevelAll();
|
||||
Select0Provider<ISelect<TNavigate>, TNavigate>.GetAllFieldExpressionTreeInfo af = null;
|
||||
(ReadAnonymousTypeInfo map, string field) mf = default;
|
||||
if (selectExp == null) af = subSelect.GetAllFieldExpressionTreeLevelAll();
|
||||
else mf = subSelect.GetExpressionField(selectExp);
|
||||
var sbSql = new StringBuilder();
|
||||
var sbDic = getWhereDic();
|
||||
foreach (var sbd in sbDic)
|
||||
{
|
||||
subSelect._where.Clear();
|
||||
subSelect.Where(sbd.Key).Where(oldWhere).Limit(takeNumber);
|
||||
sbSql.Append("\r\nUNION ALL\r\nselect * from (").Append(subSelect.ToSql(af.Field)).Append(") ftb");
|
||||
sbSql.Append("\r\nUNION ALL\r\nselect * from (").Append(subSelect.ToSql(selectExp == null ? af.Field : mf.field)).Append(") ftb");
|
||||
}
|
||||
sbSql.Remove(0, 13);
|
||||
if (sbDic.Count == 1) sbSql.Remove(0, 15).Remove(sbSql.Length - 5, 5);
|
||||
sbDic.Clear();
|
||||
subList = subSelect.ToListAfPrivate(sbSql.ToString(), af, null);
|
||||
if (selectExp == null) subList = subSelect.ToListAfPrivate(sbSql.ToString(), af, null);
|
||||
else subList = subSelect.ToListMrPrivate<TNavigate>(sbSql.ToString(), mf, null);
|
||||
sbSql.Clear();
|
||||
}
|
||||
else
|
||||
@ -658,7 +688,8 @@ namespace FreeSql.Internal.CommonProvider
|
||||
sbDic.Clear();
|
||||
}
|
||||
subSelect.Where(oldWhere);
|
||||
subList = subSelect.ToList(true);
|
||||
if (selectExp == null) subList = subSelect.ToList(true);
|
||||
else subList = subSelect.ToList<TNavigate>(selectExp);
|
||||
}
|
||||
|
||||
if (subList.Any() == false)
|
||||
@ -760,7 +791,10 @@ namespace FreeSql.Internal.CommonProvider
|
||||
subSelect.InnerJoin(sbJoin.ToString());
|
||||
sbJoin.Clear();
|
||||
|
||||
var af = subSelect.GetAllFieldExpressionTreeLevelAll();
|
||||
Select0Provider<ISelect<TNavigate>, TNavigate>.GetAllFieldExpressionTreeInfo af = null;
|
||||
(ReadAnonymousTypeInfo map, string field) mf = default;
|
||||
if (selectExp == null) af = subSelect.GetAllFieldExpressionTreeLevelAll();
|
||||
else mf = subSelect.GetExpressionField(selectExp);
|
||||
(string field, ReadAnonymousTypeInfo read)? otherData = null;
|
||||
var sbSql = new StringBuilder();
|
||||
|
||||
@ -814,7 +848,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
subSelect._where.Clear();
|
||||
subSelect.Where(sbd.Key).Where(oldWhere).Limit(takeNumber);
|
||||
sbSql.Append("\r\nUNION ALL\r\nselect * from (").Append(subSelect.ToSql($"{af.Field}{otherData?.field}")).Append(") ftb");
|
||||
sbSql.Append("\r\nUNION ALL\r\nselect * from (").Append(subSelect.ToSql($"{(selectExp == null ? af.Field : mf.field)}{otherData?.field}")).Append(") ftb");
|
||||
}
|
||||
sbSql.Remove(0, 13);
|
||||
if (sbDic.Count == 1) sbSql.Remove(0, 15).Remove(sbSql.Length - 5, 5);
|
||||
@ -838,10 +872,11 @@ namespace FreeSql.Internal.CommonProvider
|
||||
sbDic.Clear();
|
||||
}
|
||||
subSelect.Where(oldWhere);
|
||||
sbSql.Append(subSelect.ToSql($"{af.Field}{otherData?.field}"));
|
||||
sbSql.Append(subSelect.ToSql($"{(selectExp == null ? af.Field : mf.field)}{otherData?.field}"));
|
||||
}
|
||||
|
||||
subList = subSelect.ToListAfPrivate(sbSql.ToString(), af, otherData == null ? null : new[] { (otherData.Value.field, otherData.Value.read, midList) });
|
||||
if (selectExp == null) subList = subSelect.ToListAfPrivate(sbSql.ToString(), af, otherData == null ? null : new[] { (otherData.Value.field, otherData.Value.read, midList) });
|
||||
else subList = subSelect.ToListMrPrivate<TNavigate>(sbSql.ToString(), mf, otherData == null ? null : new[] { (otherData.Value.field, otherData.Value.read, midList) });
|
||||
if (subList.Any() == false)
|
||||
{
|
||||
foreach (var item in list)
|
||||
|
Loading…
x
Reference in New Issue
Block a user