SyZero.SqlSugar
1.1.9
dotnet add package SyZero.SqlSugar --version 1.1.9
NuGet\Install-Package SyZero.SqlSugar -Version 1.1.9
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="1.1.9" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyZero.SqlSugar" Version="1.1.9" />
<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 1.1.9
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SyZero.SqlSugar, 1.1.9"
#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@1.1.9
#: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=1.1.9
#tool nuget:?package=SyZero.SqlSugar&version=1.1.9
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();
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 | 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 was computed. 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.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- SqlSugarCore (>= 5.1.4.211)
- SyZero (>= 1.1.9)
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 |
|---|---|---|
| 1.1.9 | 90 | 4/19/2026 |
| 1.1.9-dev.2 | 46 | 4/19/2026 |
| 1.1.9-dev.1 | 44 | 4/17/2026 |
| 1.1.8 | 89 | 4/17/2026 |
| 1.1.6 | 86 | 4/17/2026 |
| 1.1.6-dev.1 | 43 | 4/17/2026 |
| 1.1.5 | 105 | 4/13/2026 |
| 1.1.5-dev.3 | 55 | 4/13/2026 |
| 1.1.5-dev.2 | 73 | 2/11/2026 |
| 1.1.5-dev.1 | 67 | 1/29/2026 |
| 1.1.4 | 136 | 1/2/2026 |
| 1.1.4-dev.2 | 76 | 1/2/2026 |
| 1.1.4-dev.1 | 68 | 12/30/2025 |
| 1.1.3 | 131 | 12/30/2025 |
| 1.1.3-dev.6 | 75 | 12/30/2025 |
| 1.1.3-dev.3 | 134 | 1/19/2024 |
| 1.1.3-dev.2 | 201 | 11/3/2023 |
| 1.1.3-dev.1 | 204 | 3/21/2023 |
| 1.1.2 | 431 | 3/15/2023 |
| 1.0.0 | 181 | 4/17/2026 |
Loading failed