Skip to content

Commit

Permalink
- 修复 UnionAll + OrderBy 未处理嵌套的问题;
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Dec 1, 2024
1 parent 533d798 commit 5b67288
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 155 deletions.
93 changes: 49 additions & 44 deletions Examples/base_entity/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,9 @@ static void Main(string[] args)

//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true")
//.UseAdoConnectionPool(false)
//.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=127.0.0.1;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=2")
.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=127.0.0.1;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=2")
////.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=127.0.0.1;Port=5432;Username=postgres;Password=123456;Database=toc;Pooling=true;Maximum Pool Size=2")
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToLower)
.UseNameConvert(FreeSql.Internal.NameConvertType.ToLower)

//.UseConnectionString(FreeSql.DataType.Oracle, "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=2")
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)
Expand Down Expand Up @@ -619,6 +619,53 @@ static void Main(string[] args)
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
#endregion


var dbpars = new List<DbParameter>();

var a1id1 = Guid.NewGuid();
var a1id2 = Guid.NewGuid();
//fsql.CodeFirst.IsGenerateCommandParameterWithLambda = true;
var sql1a0 = fsql.Select<User1>()
.WithParameters(dbpars)
.Where(a => a.Id == a1id1)
.OrderBy(a => a.Id)

.UnionAll(
fsql.Select<User1>()
.WithParameters(dbpars)
.Where(a => a.Id == a1id2)
.OrderByDescending(a => a.Id),

fsql.Select<User1>()
.WithParameters(dbpars)
.Where(a => a.Id == a1id2)
.OrderByDescending(a => a.Id)
)
.Where(a => a.Id == a1id1 || a.Id == a1id2)
.ToList();
var sql1a1 = fsql.Select<User1>()
.Where(a => a.Id == a1id1)
.UnionAll(
fsql.Select<User1>()
.Where(a => a.Id == a1id2)
)
.Where(a => a.Id == a1id1 || a.Id == a1id2)
.ToList();
var sql1a2 = fsql.Select<User1, UserGroup>()
.InnerJoin((a, b) => a.GroupId == b.Id)
.Where((a, b) => a.Id == a1id1)
.WithTempQuery((a, b) => new { user = a, group = b }) //匿名类型

.UnionAll(
fsql.Select<User1, UserGroup>()
.InnerJoin((a, b) => a.GroupId == b.Id)
.Where((a, b) => a.Id == a1id2)
.WithTempQuery((a, b) => new { user = a, group = b }) //匿名类型
)

.Where(a => a.user.Id == a1id1 || a.user.Id == a1id2)
.ToList();

fsql.Aop.AuditValue += (_, e) =>
{

Expand Down Expand Up @@ -1676,48 +1723,6 @@ static void Main(string[] args)
var sqlskdfj = fsql.Select<object>().AsType(typeof(BBB)).ToSql(a => new CCC());


var dbpars = new List<DbParameter>();

var a1id1 = Guid.NewGuid();
var a1id2 = Guid.NewGuid();
//fsql.CodeFirst.IsGenerateCommandParameterWithLambda = true;
var sql1a0 = fsql.Select<User1>()
.WithParameters(dbpars)
.Where(a => a.Id == a1id1)

.UnionAll(
fsql.Select<User1>()
.WithParameters(dbpars)
.Where(a => a.Id == a1id2),

fsql.Select<User1>()
.WithParameters(dbpars)
.Where(a => a.Id == a1id2)
)
.Where(a => a.Id == a1id1 || a.Id == a1id2)
.ToSql();
var sql1a1 = fsql.Select<User1>()
.Where(a => a.Id == a1id1)
.UnionAll(
fsql.Select<User1>()
.Where(a => a.Id == a1id2)
)
.Where(a => a.Id == a1id1 || a.Id == a1id2)
.ToSql();
var sql1a2 = fsql.Select<User1, UserGroup>()
.InnerJoin((a, b) => a.GroupId == b.Id)
.Where((a, b) => a.Id == a1id1)
.WithTempQuery((a, b) => new { user = a, group = b }) //匿名类型

.UnionAll(
fsql.Select<User1, UserGroup>()
.InnerJoin((a, b) => a.GroupId == b.Id)
.Where((a, b) => a.Id == a1id2)
.WithTempQuery((a, b) => new { user = a, group = b }) //匿名类型
)

.Where(a => a.user.Id == a1id1 || a.user.Id == a1id2)
.ToSql();


var ddlsql01 = fsql.CodeFirst.GetComparisonDDLStatements<StringNulable>();
Expand Down
109 changes: 0 additions & 109 deletions FreeSql/FreeSql.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ public ISelect<T1> UnionAll(params ISelect<T1>[] querys)
querys = querys?.Where(q => q != null).ToArray();
if (querys?.Any() != true) return this;
var ret = (_orm as BaseDbProvider).CreateSelectProvider<T1>(null) as Select1Provider<T1>;
var sb = new StringBuilder().Append(LocalGetQuerySql(this));
var sb = new StringBuilder().Append(this._select).Append(" * from (").Append(LocalGetQuerySql(this)).Append(") ftb");
foreach (var select2 in querys)
sb.Append(" \r\nUNION ALL \r\n").Append(LocalGetQuerySql(select2));
sb.Append(" \r\nUNION ALL \r\nselect * from (").Append(LocalGetQuerySql(select2)).Append(") ftb");
ret.WithSql(sb.ToString());
sb.Clear();
ret._commandTimeout = _commandTimeout;
Expand Down

0 comments on commit 5b67288

Please sign in to comment.