Shipeng.Data.SqlSugar 4.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Shipeng.Data.SqlSugar --version 4.1.0
                    
NuGet\Install-Package Shipeng.Data.SqlSugar -Version 4.1.0
                    
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="Shipeng.Data.SqlSugar" Version="4.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Shipeng.Data.SqlSugar" Version="4.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Shipeng.Data.SqlSugar" />
                    
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 Shipeng.Data.SqlSugar --version 4.1.0
                    
#r "nuget: Shipeng.Data.SqlSugar, 4.1.0"
                    
#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 Shipeng.Data.SqlSugar@4.1.0
                    
#: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=Shipeng.Data.SqlSugar&version=4.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Shipeng.Data.SqlSugar&version=4.1.0
                    
Install as a Cake Tool

Shipeng.Data.SqlSugar

Shipeng.Data.SqlSugar 是基于 SqlSugar 的数据访问包,提供仓储、分页、动态查询条件、事务过滤器、工作单元和 DI 注册能力。它适合已经选择 SqlSugar 作为 ORM 的后台系统、管理系统和业务服务。

安装

dotnet add package Shipeng.Data.SqlSugar

适用场景

  • 项目使用 SqlSugarCore 访问 SQL Server、MySQL、PostgreSQL、Oracle、SQLite 等数据库。
  • 需要统一分页返回模型、查询参数模型和条件表达式处理。
  • 需要在应用服务或 Controller 层通过特性启用事务。
  • 需要封装常见 CRUD、SQL 执行、存储过程和分页查询。

主要类型

  • SqlSugarServiceCollectionExtensions:注册 SqlSugar 服务和仓储的 DI 扩展入口。
  • SqlSugarUnitOfWorkAttribute:声明式事务特性,适合应用服务方法或接口方法。
  • SqlSugarUnitOfWorkFilter:事务过滤器实现。
  • SqlSugarPagedListPagedModelPagedQueryableExtensions:分页查询模型和扩展。
  • ConditionsAttributeConditionsTypeSymbolAttributeQueryParameter:动态查询条件描述。
  • SqlProfiler:SQL 执行分析/输出辅助。
  • ConfigureExternalServicesExtenisons:SqlSugar 外部服务配置扩展。

基本用法

using Shipeng.Foundation.Data.SqlSugar;

var builder = WebApplication.CreateBuilder(args);

// 从配置读取连接字符串和数据库类型后注册 SqlSugar。
// builder.Services.AddSqlSugar(builder.Configuration);

var app = builder.Build();
app.Run();

动态查询建议

public sealed class UserQuery
{
    [Conditions(ConditionsType.Equal)]
    public string? Status { get; set; }

    [Conditions(ConditionsType.Like)]
    public string? Keyword { get; set; }
}

使用建议

  • 事务只包住需要原子性的写操作,不要把远程 HTTP、消息发送等长耗时操作放进数据库事务。
  • 分页必须明确排序字段,避免数据库在大表上产生不稳定分页。
  • SQL 日志在生产环境应脱敏输出,避免记录身份证、手机号、token、密钥等敏感值。
  • 仓储只引用业务需要的数据库包,不要在上层项目重复引用无关 ORM。

API Reference / API 索引

完整公开类型、方法、属性签名请查看 API_REFERENCE.md。该文件从源码 public 声明生成,用于补充 README 中的场景说明和示例。

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Shipeng.Data.SqlSugar:

Package Downloads
Shipeng.Data.Hybrid

Hybrid MongoDB and SqlSugar paging helper package for read-model scenarios that query MongoDB first and fall back to SQL data when needed.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.1.1 157 6/30/2026
4.1.0 148 6/30/2026

4.1.0: Split the original monolithic foundation library into focused Shipeng.* NuGet packages. Consumers can reference authentication, MongoDB, SqlSugar, EF Core, database index, third-party integration, logging, mapping, payment, and hybrid paging capabilities on demand.