![]() |
VOOZH | about |
dotnet add package SyZero.SqlSugar --version 1.1.9
NuGet\Install-Package SyZero.SqlSugar -Version 1.1.9
<PackageReference Include="SyZero.SqlSugar" Version="1.1.9" />
<PackageVersion Include="SyZero.SqlSugar" Version="1.1.9" />Directory.Packages.props
<PackageReference Include="SyZero.SqlSugar" />Project file
paket add SyZero.SqlSugar --version 1.1.9
#r "nuget: SyZero.SqlSugar, 1.1.9"
#:package SyZero.SqlSugar@1.1.9
#addin nuget:?package=SyZero.SqlSugar&version=1.1.9Install as a Cake Addin
#tool nuget:?package=SyZero.SqlSugar&version=1.1.9Install as a Cake Tool
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
}
]
}
}
SyZeroDbContextvar builder = WebApplication.CreateBuilder(args);
builder.AddSyZero();
builder.Services.AddSyZeroSqlSugar();
var app = builder.Build();
app.UseSyZero();
app.InitTables();
app.Run();
DbContextusing 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 返回可继续组合的查询对象,不会先把数据全部加载到内存。ILogger 输出原始 SQL 和参数。| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 netstandard2.1 is compatible. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 2 NuGet packages that depend on SyZero.SqlSugar:
| Package | Downloads |
|---|---|
|
SyZero.Example2.Core
Package Description |
|
|
SyZero.Example1.Core
Package Description |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.9 | 107 | 4/19/2026 |
| 1.1.9-dev.2 | 56 | 4/19/2026 |
| 1.1.9-dev.1 | 56 | 4/17/2026 |
| 1.1.8 | 104 | 4/17/2026 |
| 1.1.6 | 100 | 4/17/2026 |
| 1.1.6-dev.1 | 50 | 4/17/2026 |
| 1.1.5 | 118 | 4/13/2026 |
| 1.1.5-dev.3 | 64 | 4/13/2026 |
| 1.1.5-dev.2 | 84 | 2/11/2026 |
| 1.1.5-dev.1 | 73 | 1/29/2026 |
| 1.1.4 | 147 | 1/2/2026 |
| 1.1.4-dev.2 | 83 | 1/2/2026 |
| 1.1.4-dev.1 | 74 | 12/30/2025 |
| 1.1.3 | 141 | 12/30/2025 |
| 1.1.3-dev.6 | 83 | 12/30/2025 |
| 1.1.3-dev.3 | 139 | 1/19/2024 |
| 1.1.3-dev.2 | 204 | 11/3/2023 |
| 1.1.3-dev.1 | 209 | 3/21/2023 |
| 1.1.2 | 435 | 3/15/2023 |
| 1.0.0 | 195 | 4/17/2026 |