Group By对于bool字段生成的SQL有问题 返回

SqlSugar 沟通中
5 249
该叫什么 =_= 发布于2025/11/20
悬赏:0 飞吻
/// <summary>
/// 审批标志
/// </summary>
[SugarColumn(ColumnName = "SPBZ", IsNullable = false)]
public bool SPBZ { get; set; } = false;

在5.4.1.199版本的生成是正常的
在5.4.1.208版本生成就变成了

GROUP BY [m].[Id],[m].[Remarks],[m].[GSH],[n].[GSMC],( [m].[SPBZ]=1 ),( [m].[Delete]=1 )


热忱回答5

  • fate sta fate sta VIP0
    2025/11/20

    不能重现,需要提供完整DEMO

    0 回复
  • fate sta fate sta VIP0
    2025/11/20
    0 回复
  • =_= =_= VIP0
    2025/11/20
    using SqlSugar;
    
    namespace Test
    {
        public class Program
        {
            private static void Main(string[] args)
            {
                SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
                {
                    DbType = DbType.SqlServer,
                    ConnectionString = "server=127.0.0.1,1433;database=Link;uid=sa;pwd=QWE123qwe;TrustServerCertificate=True;",
                    IsAutoCloseConnection = true
                });
    
                db.CodeFirst.InitTables<DocumentH>();
                db.CodeFirst.InitTables<DocumentB>();
    
                var tempTable = db.Queryable<DocumentH>()
                    .LeftJoin<DocumentB>((m, o) => m.Id == o.HId && o.WriteOffDate == null)
                    .GroupBy((m, o) => new { m.Id, m.SPBZ, m.Delete})
                    .Select((m, o) => new
                    {
                        Id = m.Id,
                        SPBZ = m.SPBZ,
                        Delete = m.Delete,
                        NoWriteOffNumber = SqlFunc.AggregateCount(o.Id)
                    });
                Console.WriteLine(tempTable.ToSqlString());
            }
            public class DocumentH
            {
                /// <summary>
                /// 单据编号
                /// </summary>
                [SugarColumn(ColumnName = "Id", Length = 50, IsPrimaryKey = true, IsNullable = false)]
                public string Id { get; set; } = string.Empty;
    
                /// <summary>
                /// 审批标志
                /// </summary>
                [SugarColumn(ColumnName = "SPBZ", IsNullable = false)]
                public bool SPBZ { get; set; } = false;
    
                /// <summary>
                /// 删除标志
                /// </summary>
                [SugarColumn(ColumnName = "Delete", IsNullable = false)]
                public bool Delete { get; set; } = false;
    
                /// <summary>
                /// 明细信息
                /// </summary>
                [Navigate(NavigateType.OneToMany, nameof(DocumentB.HId))]//BookA表中的studenId
                public List<DocumentB>? Items { get; set; }
            }
    
            public class DocumentB
            {
                /// <summary>
                /// 主键Id
                /// </summary>
                [SugarColumn(ColumnName = "Id", IsIdentity = true, IsPrimaryKey = true, IsNullable = false)]
                public long Id { get; set; }
    
                /// <summary>
                /// 单据编号
                /// </summary>
                [SugarColumn(ColumnName = "HId", Length = 50, IsNullable = false)]
                public string HId { get; set; } = string.Empty;
    
                /// <summary>
                /// 核销日期
                /// </summary>
                [SugarColumn(ColumnName = "WriteOffDate", IsNullable = true)]
                public DateTime? WriteOffDate { get; set; } = null;
            }
        }
    }

    @fate sta:最新的208版本
    image.png

    image.png

    0 回复
  • fate sta fate sta VIP0
    2025/11/20

     SqlSugarCore 5.1.4.209

      已修复 ,过五分钟后安装 

    0 回复
  • =_= =_= VIP0
    2025/11/20

    @fate sta:ok

    0 回复