mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 04:18:16 +08:00
- 修复 ISelect.AsTable union all 查询对 count/max/min/avg/sum 的别名 bug;#157
This commit is contained in:
@ -881,6 +881,21 @@ namespace FreeSql.Tests.Odbc.Dameng
|
||||
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_TOPIC22_T1\" 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 TiOtmModel1
|
||||
|
@ -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
|
||||
|
@ -965,6 +965,21 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
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);
|
||||
|
||||
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_topic` a) ftb UNION ALLSELECT * from (SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` 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_topic` a) ftb UNION ALLSELECT * from (SELECT count(1) as1 FROM `tb_topic` 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
|
||||
|
@ -881,6 +881,21 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
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_TOPIC22_T1\" 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 TiOtmModel1
|
||||
|
@ -937,6 +937,21 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
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);
|
||||
|
||||
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_topic\" a) ftb UNION ALLSELECT * from (SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" 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_topic\" a) ftb UNION ALLSELECT * from (SELECT count(1) as1 FROM \"tb_topic\" 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
|
||||
|
@ -831,6 +831,21 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
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
|
||||
|
Reference in New Issue
Block a user