- 修复 ISelect.AsTable union all 查询对 count/max/min/avg/sum 的别名 bug;#157

This commit is contained in:
28810
2019-12-16 18:02:20 +08:00
parent fe7b7e5012
commit 51494c31a2
15 changed files with 357 additions and 199 deletions

View File

@ -850,6 +850,21 @@ namespace FreeSql.Tests.Odbc.Default
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_topic22AsTable1] a LEFT JOIN TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = @bname", sql);
query = select.AsTable((_, old) => old).AsTable((_, old) => old);
sql = query.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT * from (SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a) ftb UNION ALLSELECT * from (SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a) ftb", sql);
query.ToList();
query = select.AsTable((_, old) => old).AsTable((_, old) => old);
sql = query.ToSql("count(1) as1").Replace("\r\n", "");
Assert.Equal("SELECT * from (SELECT count(1) as1 FROM [tb_topic22] a) ftb UNION ALLSELECT * from (SELECT count(1) as1 FROM [tb_topic22] a) ftb", sql);
query.Count();
select.AsTable((_, old) => old).AsTable((_, old) => old).Max(a => a.Id);
select.AsTable((_, old) => old).AsTable((_, old) => old).Min(a => a.Id);
select.AsTable((_, old) => old).AsTable((_, old) => old).Sum(a => a.Id);
select.AsTable((_, old) => old).AsTable((_, old) => old).Avg(a => a.Id);
}
public class TestInclude_OneToManyModel1