SyZero.SqlSugar
10.0.0
dotnet add package SyZero.SqlSugar --version 10.0.0
NuGet\Install-Package SyZero.SqlSugar -Version 10.0.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="SyZero.SqlSugar" Version="10.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyZero.SqlSugar" Version="10.0.0" />
<PackageReference Include="SyZero.SqlSugar" />
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 SyZero.SqlSugar --version 10.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SyZero.SqlSugar, 10.0.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 SyZero.SqlSugar@10.0.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=SyZero.SqlSugar&version=10.0.0
#tool nuget:?package=SyZero.SqlSugar&version=10.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SyZero.SqlSugar
SyZero 框架的 SqlSugar ORM 集成模块。
安装
dotnet add package SyZero.SqlSugar
配置
在 appsettings.json 中配置数据库连接:
{
"ConnectionString": {
"Type": "MySql",
"Master": "Server=localhost;Database=MyDb;User=root;Password=123456;",
"Slave": [
{
"ConnectionString": "Server=localhost;Database=MyDbRead;User=root;Password=123456;",
"HitRate": 10
}
]
}
}
注册
使用默认 SyZeroDbContext
var builder = WebApplication.CreateBuilder(args);
builder.AddSyZero();
builder.Services.AddSyZeroSqlSugar(builder.Configuration);
var app = builder.Build();
app.UseSyZero();
app.InitTables();
app.Run();
使用自定义 DbContext
using Microsoft.Extensions.Logging;
using SqlSugar;
using SyZero.SqlSugar.DbContext;
public class MyDbContext : SyZeroDbContext
{
public MyDbContext(ConnectionConfig config, ILoggerFactory loggerFactory)
: base(config, loggerFactory)
{
}
}
builder.Services.AddSyZeroSqlSugar<MyDbContext>();
使用示例
using SyZero.Domain.Repository;
public class UserService
{
private readonly IRepository<User> _userRepository;
private readonly IUnitOfWork _unitOfWork;
public UserService(IRepository<User> userRepository, IUnitOfWork unitOfWork)
{
_userRepository = userRepository;
_unitOfWork = unitOfWork;
}
public Task<User> CreateUserAsync(User user)
{
return _userRepository.AddAsync(user);
}
public IQueryable<User> GetActiveUsers()
{
return _userRepository.GetList(x => x.IsActive);
}
public Task ExecuteInTransactionAsync(Func<Task> action)
{
return _unitOfWork.ExecuteInTransactionAsync(action);
}
}
说明
ISyZeroDbContext、IRepository<>、IUnitOfWork默认按Scoped注册。- 同一请求作用域内,仓储和工作单元会共享同一个
DbContext实例。 GetList/GetPaged返回可继续组合的查询对象,不会先把数据全部加载到内存。- SQL 日志默认通过
ILogger输出原始 SQL 和参数。
| Product | Versions 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.
-
net10.0
- Castle.Core (>= 5.2.1)
- Dynamitey (>= 2.0.10.189)
- ImpromptuInterface (>= 7.0.1)
- Microsoft.Data.SqlClient (>= 7.1.1)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Caching.Memory (>= 10.0.13)
- Microsoft.Extensions.Configuration (>= 10.0.13)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.13)
- Microsoft.Extensions.Configuration.Json (>= 10.0.13)
- Microsoft.Extensions.DependencyInjection (>= 10.0.13)
- Microsoft.Extensions.DependencyModel (>= 10.0.13)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.13)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.23.0)
- Newtonsoft.Json (>= 13.0.4)
- Refit (>= 8.0.0)
- Snowflake.Core (>= 2.0.0)
- SQLitePCLRaw.lib.e_sqlite3 (>= 2.1.14)
- SqlSugarCore (>= 5.1.4.221)
- System.IdentityModel.Tokens.Jwt (>= 8.23.0)
- System.Linq.Dynamic.Core (>= 1.6.6)
- System.Security.Cryptography.Pkcs (>= 10.0.13)
- SyZero.Core (>= 10.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on SyZero.SqlSugar:
| Package | Downloads |
|---|---|
|
SyZero.Example2.Core
Package Description |
|
|
SyZero.Example1.Core
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.0 | 95 | 10/23/2026 |
| 9.1.0 | 82 | 10/22/2026 |
| 1.2.0 | 79 | 10/22/2026 |
| 1.2.0-dev.1 | 53 | 10/22/2026 |
| 1.1.9 | 152 | 4/19/2026 |
| 1.1.9-dev.2 | 87 | 4/19/2026 |
| 1.1.9-dev.1 | 80 | 4/17/2026 |
| 1.1.8 | 135 | 4/17/2026 |
| 1.1.6 | 135 | 4/17/2026 |
| 1.1.6-dev.1 | 80 | 4/17/2026 |
| 1.1.5 | 152 | 4/13/2026 |
| 1.1.5-dev.3 | 94 | 4/13/2026 |
| 1.1.5-dev.2 | 114 | 2/11/2026 |
| 1.1.5-dev.1 | 102 | 1/29/2026 |
| 1.1.4 | 181 | 1/2/2026 |
| 1.1.4-dev.2 | 107 | 1/2/2026 |
| 1.1.4-dev.1 | 98 | 12/30/2025 |
| 1.1.3 | 168 | 12/30/2025 |
| 1.1.3-dev.6 | 108 | 12/30/2025 |
| 1.0.0 | 232 | 4/17/2026 |
Loading failed