Liwendong.Frameworks.Data.SqlSugarExtend 3.2.1

dotnet add package Liwendong.Frameworks.Data.SqlSugarExtend --version 3.2.1
                    
NuGet\Install-Package Liwendong.Frameworks.Data.SqlSugarExtend -Version 3.2.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Liwendong.Frameworks.Data.SqlSugarExtend" Version="3.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Liwendong.Frameworks.Data.SqlSugarExtend" Version="3.2.1" />
                    
Directory.Packages.props
<PackageReference Include="Liwendong.Frameworks.Data.SqlSugarExtend" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Liwendong.Frameworks.Data.SqlSugarExtend --version 3.2.1
                    
#r "nuget: Liwendong.Frameworks.Data.SqlSugarExtend, 3.2.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Liwendong.Frameworks.Data.SqlSugarExtend@3.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Liwendong.Frameworks.Data.SqlSugarExtend&version=3.2.1
                    
Install as a Cake Addin
#tool nuget:?package=Liwendong.Frameworks.Data.SqlSugarExtend&version=3.2.1
                    
Install as a Cake Tool

Liwendong.Frameworks.Data.SqlSugarExtend

主要是基于 SqlSugar 进行扩展操作

更新日志

版本历史

3.2.1 (2026-10-17)

  • 修复:NormalizeDuration 三元两分支相同,未限制有效期时正确返回 int.MaxValue
  • 修复:Update(info, List<string> columns) 更新列被主键过滤后为空时误退化为全列更新,改为直接不执行
  • 修复:SetOrderBy 排序项已带 ASC/DESC 时重复追加方向生成 ORDER BY Id DESC Asc,改为仅在排序项缺省方向时追加
  • 修复:UpdateIgnoreColumn(T, ...) 两个重载补 info == null 判空(对齐 Update(T))
  • 修复:UseTran 事务失败且 ErrorException 为 null 时 throw 抛 NRE,改为抛 EasyErrorException("事务执行失败");泛型/非泛型两处实现收敛为 SqlSugarDb.ExecuteTranCore
  • 修复:GetUpdateColumnName/GetNotUpdateColumnName 会把默认排除列 AddRange 进调用方传入的列表(副作用),改为先拷贝再操作;补 source/info 判空,删除未使用局部变量
  • 修复:BaseQueryParameter.OrderBySql 缓存先写 key 后写内容的竞态,改为先算结果 → 写缓存 → 最后写 key
  • 修复:SqlSugarDb 慢 SQL AOP 回调中 client == null 判断恒假,改为判 _disposed
  • 修复:慢 SQL 阈值 SqlSugarDb 20000ms 与 SqlSugarConfig 5000ms 不一致,统一为 5000ms
  • 修复:GetInfo 排序默认值 SqlSugarBLLBase(Desc)与 SugarHandler(Asc)不一致,统一为 Asc(注意:依赖 Desc 默认排序的调用方需显式传 OrderByType.Desc)
  • 修复:SqlSugarDALBase 未配置 ConnectionStrings:default 时给出明确报错"ConnectionStrings:default 未配置"
  • 优化:MemoryCache/RedisCache 的 GetOrCreate 逐字重复实现抽取为 SqlSugarHelper.GetOrCreateCacheItem
  • 优化:GetUpdateColumnName 两个重载的属性比对循环抽取为 DiffUpdateColumns;Update(T,Action,...) 与 UpdateIgnoreColumn(T,Action,...) 抽取为 UpdateByChangedColumns
  • 优化:批量 Update 的 UpdateColumns/WhereColumns/SetColumns 返回值处理风格统一(全部回写)
  • 优化:SqlSugarIFWhereOption、SqlSugarOrderByOption 补充 XML 注释
  • 不兼容变更:Extensions.Pager 返回类型由 void 改为 ISugarQueryable<T>(可链式调用,不再依赖可变语义;源码兼容,重新编译即可,二进制不兼容)

3.2.0

目标框架扩展版本,无行为变更。

新增

  • 目标框架由 netcoreapp3.1;net451;net46;net48 扩展为 net8.0;netcoreapp3.1;net451;net46;net47;net48;net8.0 与 netcoreapp3.1 同档使用 SqlSugarCore 5.1.4.198(API 行为一致),.NET Framework 侧沿用 SqlSugar 5.1.4.198。

3.1.0

本次为缺陷修复版本,包含少量不兼容变更,升级请留意下方说明。

修复

  • 缓存失效不完整:UpdateSetColumn 全部重载、Add(Dictionary<string,object>) 之前未调用 RemoveDataCache, 开启 EnabledCache 后会一直读到脏数据(SqlSugar 缓存默认有效期为 int.MaxValue 秒)。现已全部补齐。
  • 全表删除/更新风险:Delete(Expression)、Delete(BaseQueryParameter)、Update(Dictionary, where)、 UpdateSetColumn(wheres, ...)、Any、GetInfo、GetList 在条件为 null 时不再默认执行全表操作,改为抛出 ArgumentNullException。确实需要操作全部数据时,请显式传入 it => true。
  • 连接泄漏:SqlSugarDb 实现 IDisposable;调用方传入的 ConnectionConfig 会按配置兜底开启 IsAutoCloseConnection(SqlSugar 默认为 false)。
  • ORDER BY 注入面:BaseQueryParameter.OrderBySql 由黑名单过滤改为白名单校验, 仅接受 字段名 [ASC|DESC](多个字段逗号分隔),非法内容直接丢弃。
  • 日志安全:慢 SQL / SQL 异常日志默认不再记录参数值,避免手机号、身份证、Token 等敏感数据落盘; 需要排查问题时可开启 SqlSugarConfig:LogSqlParameterValue。SQL 异常日志由 Warn 级别改为 Exception 级别。
  • 主键过滤失效:Update(info, List<string> columns) 之前用"数据库列名"过滤"实体属性名", 实体存在 SugarColumn(ColumnName=...) 时主键排除不生效,现改为按属性名匹配(新增 GetPrimaryKeyPropertyNames)。
  • 变更检测失效:Update(info, Action, ...) 之前使用浅拷贝快照,引用类型属性与源对象共享实例导致修改检测不到, 现改为深拷贝(SqlSugarHelper.CloneEntity,内部用序列化实现,循环引用已处理,失败时降级为浅拷贝)。
  • 表达式解析遗漏:GetColumnName / UpdateIgnoreColumn 之前不处理装箱产生的 UnaryExpression, 传入值类型属性(如 x => x.Id)时会被静默忽略;现已统一由 GetMemberNames 处理。
  • 空引用与空集合:补齐 Update(info, columns)、Update(List)、UpdateIgnoreColumn(List)、Add(Dictionary)、 RemoveCache 等方法的判空保护;移除 RemoveCache 中可能对非线程安全缓存实现的并发访问。
  • Redis 资源与竞态:RedisCache 按连接串复用实例,避免重复触发 CSRedisCoreHelper 全局初始化。
  • 配置污染:不再修改全局静态的 SqlConfig.SqlSugarConfig.RedisConfig.ConnectionString; ConfigureExternalServices 由覆盖改为合并,保留调用方自定义配置。
  • NotAny 由 Func<T,bool> 改为 Expression<Func<T,bool>>,原写法无法被翻译成 SQL。

不兼容变更

  • SqlSugarBLLBase 的 Add / Update / UpdateIgnoreColumn / UpdateSetColumn 返回值由 void 改为 bool。 忽略返回值的调用代码无需改动;若有派生类重写了这些方法,需要同步修改返回类型。
  • NotAny 参数类型由 Func<T,bool> 改为 Expression<Func<T,bool>>(lambda 写法不变)。
  • Delete / Update(Dictionary) / UpdateSetColumn 在缺少条件时由"执行全表操作"改为抛出异常。
  • BaseQueryParameter.OrderBySql 不再支持 Id DESC, CASE WHEN ... 这类表达式写法,仅接受字段名与排序方向。
  • 慢 SQL / SQL 异常日志默认不再输出参数值。

新增配置项(SqlSugarConfig 节点)

配置 默认值 说明
LogSqlParameterValue false 是否在日志中输出 SQL 参数值
EnabledSlowSqlLog true 是否输出慢 SQL 日志
ForceAutoCloseConnection true 是否兜底开启自动关闭连接

静态项 SqlSugarCacheOptions.MaxCacheDurationSeconds(默认 0 表示不限制)可用于限制单条缓存的最长有效期, 作为缓存未被失效时的兜底手段。

注意:SqlSugarClient 非线程安全,请勿在多线程间共享同一个 SqlSugarDb / SugarHandler<T> 实例; 不再使用时请调用 Dispose() 释放数据库连接。

3.0.0

  • [3.0.0] 重新优化了继承方法,减去没有必要的继承
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
.NET Framework net451 is compatible.  net452 was computed.  net46 is compatible.  net461 was computed.  net462 was computed.  net463 was computed.  net47 is compatible.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.2.1 74 10/20/2026
3.0.1 159 8/14/2026
3.0.0 141 8/14/2026 3.0.0 is deprecated because it has critical bugs.
2.4.5 164 5/11/2026
2.4.4 150 5/9/2026
2.4.3 155 5/9/2026
2.4.1 334 9/29/2025
2.4.0 321 9/1/2025
2.3.0 367 8/26/2025
2.2.4 368 8/26/2025
2.2.3 222 8/23/2025
2.2.2 294 8/12/2025
2.2.1 349 8/8/2025
2.2.0 360 8/8/2025
2.1.1 190 8/2/2025
2.1.0 180 8/2/2025
2.0.1 256 7/29/2025
2.0.0 624 7/24/2025
1.6.0 582 7/21/2025
1.5.0 342 5/6/2025
Loading failed

修复缓存失效不全、全表更新删除风险、连接泄漏、ORDER BY注入面;详见 readme.md