Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WithSql存在GroupBy时,自定义返回列,主键key无法正常as为自定义的指定列名 #1141

Closed
sunnyfancore opened this issue Jun 2, 2022 · 0 comments

Comments

@sunnyfancore
Copy link

sunnyfancore commented Jun 2, 2022

问题描述及重现步骤:

ISelect<WorkReportCountObj> iSelect = _freeSql.Select<WorkReportCountObj>()
                  .WithSql( //待审批
                     _freeSql.Select<SysCheckForm, SysMessage>()
                     .InnerJoin((a1, a2) => a1.Id == a2.WorkId)
                     .Where((a1, a2) => a2.Type == 1 && a2.IsDelete == 1 && postIds.Contains(a2.UserDepartmentPostId))
                     .WhereIf(searchDto.start_time.HasValue, (a1, a2) => a2.RecvDate >= searchDto.start_time)
                     .WhereIf(searchDto.end_time.HasValue, (a1, a2) => a2.RecvDate <= searchDto.end_time)
                     .GroupBy((a1, a2) => a2.UserDepartmentPostId)
                     .ToSql(r1 => new WorkReportCountObj()
                     {
                         uid = r1.Key,
                         count = r1.Count(),
                         type = 1,
                         id_type = 2
                     }, FieldAliasOptions.AsProperty))

上述语句会输出SELECT UserDepartmentPostId 而不是我想要的SELECT UserDepartmentPostId AS uid

当语句为以下时,可以正常输出

 ISelect<WorkReportCountObj> iSelect = _freeSql.Select<WorkReportCountObj>()
                  .WithSql( //待审批
                     _freeSql.Select<SysCheckForm, SysMessage>()
                     .InnerJoin((a1, a2) => a1.Id == a2.WorkId)
                     .Where((a1, a2) => a2.Type == 1 && a2.IsDelete == 1 && postIds.Contains(a2.UserDepartmentPostId))
                     .WhereIf(searchDto.start_time.HasValue, (a1, a2) => a2.RecvDate >= searchDto.start_time)
                     .WhereIf(searchDto.end_time.HasValue, (a1, a2) => a2.RecvDate <= searchDto.end_time)
                     .GroupBy((a1, a2) => a2.UserDepartmentPostId)
                     .ToSql(r1 => new WorkReportCountObj()
                     {
                         uid = r1.Value.Item2.UserDepartmentPostId,
                         count = r1.Count(),
                         type = 1,
                         id_type = 2
                     }, FieldAliasOptions.AsProperty))

输出语句为SELECT UserDepartmentPostId AS uid ,此输出是正确的

数据库的具体版本

mysql5.7

安装的包


.net framework/. net core? 及具体版本

. net core3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants