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

使用子查询报错 #1205

Closed
okyouwin opened this issue Aug 5, 2022 · 5 comments
Closed

使用子查询报错 #1205

okyouwin opened this issue Aug 5, 2022 · 5 comments

Comments

@okyouwin
Copy link

okyouwin commented Aug 5, 2022

问题描述及重现步骤:
实体类主要部分

  internal class SButtonEntity : BaseEntity
   {
       /// <summary>
       /// 页面Id
       /// </summary>
       public long PageId { get; set; }
       /// <summary>
       /// 按钮名称
       /// </summary>
       public string Name { get; set; }
  
   }

 
  internal class SPageEntity : BaseEntity
    {
        /// <summary>
        /// 页面序号  对应层级关系
        /// </summary>
        public string PageIndex { get; set; }
      
        /// <summary>
        /// 一个页面多个按钮
        /// </summary>
        public virtual List<SButtonEntity> Buttons { get; set; } = new List<SButtonEntity>();
  }
 
  public class ButtonDTO : BaseDTO
   {
       /// <summary>
       /// 按钮名称
       /// </summary>
       public string Name { get; set; }
       /// <summary>
       /// 排序
       /// </summary>
       public int Sort { get; set; }
       /// <summary>
       /// 描述
       /// </summary>
       public string Describe { get; set; }
       /// <summary>
       /// 是否被选中
       /// </summary>
       public bool IsSelect { get; set; }
   }

数据库数据

Button 
 Id	PageId
1555451690705096704	2
1555452147460608000	2
Page
Id
1
2
3
4
1549940723724455936
1554728972439392256
1554736004823388160
1555026988186603520
1555474150305435648
1555445818587222016
  var page =   _freeSql.Select<SPageEntity>().Where(a => a.IsDelete == false&&a.Id== 1554736004823388160)
                
                .ToList((a) =>
                        new {
                            all = a,
                            Buttons = _freeSql.Select<SButtonEntity>().Where((c) => c.PageId == a.Id.Value).ToList<ButtonDTO>()
                              });

如果不加上Id=1554736004823388160 这个条件就会报错 加上就正常
这是正常生成的sql :

2022-08-05 17:21:05查询耗时20 ms , sql: SELECT a.[Id] as1, a.[CreateUserId] as2, a.[UpdateUserId] as3, a.[CreateDateTime] 
                  as4, a.[UpdateDateTime] as5, a.[IsDelete] as6, a.[PageIndex] as7, a.[PageTitle] as8, a.[PageName] as9, a.[PagePath] as10, a. 
                [PageComponentPath] as11, a.[PageType] as12, a.[PageIcon] as13, a.[ClientType] as14, a.[Describe] as15, a.[Id] as16
                    FROM [S_Page] a
                    WHERE (a.[IsDelete] = 0 AND a.[Id] = 1554736004823388160)
                    2022-08-05 17:21:05查询耗时1 ms , sql: SELECT a.[Id] as1, a.[Name] as2, a.[Sort] as3, a.[Describe] as4, 0 fsql_subsel_rowidx
                    FROM [S_Button] a
                    WHERE (a.[PageId] = @exp_0)
这是异常的sql 
 
2022-08-05 17:31:05查询耗时18 ms , sql: SELECT a.[Id] as1, a.[CreateUserId] as2, a.[UpdateUserId] as3, a.[CreateDateTime] as4, a.[UpdateDateTime] as5, a.[IsDelete] as6, a.[PageIndex] as7, a.[PageTitle] as8, a.[PageName] as9, a.[PagePath] as10, a.[PageComponentPath] as11, a.[PageType] as12, a.[PageIcon] as13, a.[ClientType] as14, a.[Describe] as15, a.[Id] as16
FROM [S_Page] a
WHERE (a.[IsDelete] = 0)
2022-08-05 17:31:05查询耗时2 ms , sql: select * from (SELECT a.[Id] as1, a.[Name] as2, a.[Sort] as3, a.[Describe] as4, 0 fsql_subsel_rowidx
FROM [S_Button] a
WHERE (a.[PageId] = @exp_0)) ftb
UNION ALL
select * from (SELECT a.[Id] as1, a.[Name] as2, a.[Sort] as3, a.[Describe] as4, 1 fsql_subsel_rowidx
FROM [S_Button] a
WHERE (a.[PageId] = @exp_1)) ftb
UNION ALL
select * from (SELECT a.[Id] as1, a.[Name] as2, a.[Sort] as3, a.[Describe] as4, 2 fsql_subsel_rowidx
FROM [S_Button] a
WHERE (a.[PageId] = @exp_3)) ftb
UNION ALL
select * from (SELECT a.[Id] as1, a.[Name] as2, a.[Sort] as3, a.[Describe] as4, 3 fsql_subsel_rowidx
FROM [S_Button] a
WHERE (a.[PageId] = @exp_7)) ftb
UNION ALL
select * from (SELECT a.[Id] as1, a.[Name] as2, a.[Sort] as3, a.[Describe] as4, 4 fsql_subsel_rowidx
FROM [S_Button] a
WHERE (a.[PageId] = @exp_15)) ftb
UNION ALL
select * from (SELECT a.[Id] as1, a.[Name] as2, a.[Sort] as3, a.[Describe] as4, 5 fsql_subsel_rowidx
FROM [S_Button] a
WHERE (a.[PageId] = @exp_31)) ftb
UNION ALL
select * from (SELECT a.[Id] as1, a.[Name] as2, a.[Sort] as3, a.[Describe] as4, 6 fsql_subsel_rowidx
FROM [S_Button] a
WHERE (a.[PageId] = @exp_63)) ftb
UNION ALL
select * from (SELECT a.[Id] as1, a.[Name] as2, a.[Sort] as3, a.[Describe] as4, 7 fsql_subsel_rowidx
FROM [S_Button] a
WHERE (a.[PageId] = @exp_127)) ftb
UNION ALL
select * from (SELECT a.[Id] as1, a.[Name] as2, a.[Sort] as3, a.[Describe] as4, 8 fsql_subsel_rowidx
FROM [S_Button] a
WHERE (a.[PageId] = @exp_255)) ftb
UNION ALL
select * from (SELECT a.[Id] as1, a.[Name] as2, a.[Sort] as3, a.[Describe] as4, 9 fsql_subsel_rowidx
FROM [S_Button] a
WHERE (a.[PageId] = @exp_511)) ftb

fail: MDOpenWebApi.WebExtends.GlobalExceptionsFilter[0]
      Exception has been thrown by the target of an invocation.

数据库的具体版本
sql server 2008R2

安装的包
3.2.655

.net 及具体版本
.net6

@2881099
Copy link
Collaborator

2881099 commented Aug 5, 2022

我这里测试没重现,你能把这些代码整理成一个 console app 应用程序压缩后发出来吗

@okyouwin
Copy link
Author

okyouwin commented Aug 5, 2022 via email

@okyouwin
Copy link
Author

okyouwin commented Aug 6, 2022 via email

@okyouwin
Copy link
Author

okyouwin commented Aug 6, 2022

FreeSqlTest.zip
麻烦看一下

@2881099
Copy link
Collaborator

2881099 commented Aug 6, 2022

ToList 子查询功能,开启参数后,重复组织了相同的参数对象,导致了 bug

v3.2.666-preview20220806 修复了该问题

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