![]() |
VOOZH | about |
dotnet add package Galosys.Foundation.SqlSugar --version 26.5.19.1
NuGet\Install-Package Galosys.Foundation.SqlSugar -Version 26.5.19.1
<PackageReference Include="Galosys.Foundation.SqlSugar" Version="26.5.19.1" />
<PackageVersion Include="Galosys.Foundation.SqlSugar" Version="26.5.19.1" />Directory.Packages.props
<PackageReference Include="Galosys.Foundation.SqlSugar" />Project file
paket add Galosys.Foundation.SqlSugar --version 26.5.19.1
#r "nuget: Galosys.Foundation.SqlSugar, 26.5.19.1"
#:package Galosys.Foundation.SqlSugar@26.5.19.1
#addin nuget:?package=Galosys.Foundation.SqlSugar&version=26.5.19.1Install as a Cake Addin
#tool nuget:?package=Galosys.Foundation.SqlSugar&version=26.5.19.1Install as a Cake Tool
成熟度: 🟡 可用 — 功能完整,测试或文档可能不完善
SqlSugar ORM 框架集成模块,为 Galosys.Foundation 提供基于 SqlSugar 的数据访问层实现。
Galosys.Foundation.SqlSugar 是 SqlSugar ORM 框架在 Galosys.Foundation 框架中的集成模块。它提供了自动化的数据库连接管理、实体映射、审计字段填充、多租户支持、单元工作模式等企业级功能。
IMultiTenancy 接口实现数据隔离IMultiApplication 接口实现应用级数据隔离IDeletable 接口)SqlSugarRepository<T> 泛型仓储IUnitOfWork 接口实现事务管理<ItemGroup>
<PackageReference Include="Galosys.Foundation.SqlSugar" Version="x.x.x" />
</ItemGroup>
{
"ConnectionStrings": {
"Default": {
"ConnectionString": "Server=localhost;Database=mydb;User=root;Password=password;",
"Provider": "MySqlConnector"
}
}
}
| Provider | 数据库类型 |
|---|---|
system.data.sqlClient / microsoft.data.sqlClient |
SqlServer |
MySqlConnector |
MySql |
Npgsql |
PostgreSQL |
Oracle.ManagedDataAccess.Client |
Oracle |
Microsoft.Data.Sqlite |
SQLite |
public class ProductService
{
private readonly SqlSugarRepository<Product> _repository;
private readonly IUnitOfWork _unitOfWork;
public ProductService(
SqlSugarRepository<Product> repository,
IUnitOfWork unitOfWork)
{
_repository = repository;
_unitOfWork = unitOfWork;
}
// 查询
public async Task<List<Product>> GetProductsAsync()
{
return await _repository.AsQueryable()
.Where(p => !p.Deleted) // 软删除过滤
.ToListAsync();
}
// 新增
public async Task AddProductAsync(Product product)
{
await _repository.InsertAsync(product);
}
// 更新
public async Task UpdateProductAsync(Product product)
{
await _repository.UpdateAsync(product);
}
// 删除(软删除)
public async Task DeleteProductAsync(long id)
{
var product = await _repository.GetByIdAsync(id);
if (product != null)
{
product.Deleted = true;
await _repository.UpdateAsync(product);
}
}
}
public class OrderService
{
private readonly SqlSugarRepository<Order> _orderRepo;
private readonly SqlSugarRepository<OrderItem> _itemRepo;
private readonly IUnitOfWork _unitOfWork;
public async Task CreateOrderAsync(Order order, List<OrderItem> items)
{
await _unitOfWork.BeginTransactionAsync();
try
{
await _orderRepo.InsertAsync(order);
foreach (var item in items)
{
item.OrderId = order.Id;
await _itemRepo.InsertAsync(item);
}
await _unitOfWork.CommitAsync();
}
catch
{
await _unitOfWork.RollbackAsync();
throw;
}
}
}
[Table("products")]
public class Product : FullEntity<long>
{
[SnowflakeId]
public new long Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
[CreatedAt]
public DateTime CreatedAt { get; set; }
[CreatorId]
public long CreatorId { get; set; }
[LastModifiedAt]
public DateTime? LastModifiedAt { get; set; }
}
| 类名 | 描述 |
|---|---|
SqlSugarModule |
模块入口,实现 IModule 接口 |
SqlSugarServiceCollectionExtensions |
DI 扩展方法,注册 SqlSugar 服务 |
SqlSugarRepository<T> |
泛型仓储,继承自 SimpleClient<T> |
SqlSugarUnitOfWork |
单元工作实现,提供事务管理 |
IRepository、IUnitOfWork 等接口审计字段:模块会自动填充 [SnowflakeId]、[Ulid]、[Nanoid]、[Uuid] 等ID字段,以及 [CreatedAt]、[CreatorId]、[CreatorName]、[LastModifiedAt]、[LastModifierId]、[LastModifierName] 等审计字段。
实体映射:支持 [Table]、[Column]、[Key]、[DatabaseGenerated(Identity)]、[NotMapped]、[Description]、[DefaultValue]、[Required] 等标准特性进行实体映射配置。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. 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. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 26.5.19.1 | 96 | 5/19/2026 |
| 26.5.18.1 | 96 | 5/18/2026 |
| 26.5.15.1 | 94 | 5/15/2026 |
| 26.5.12.3 | 90 | 5/12/2026 |
| 26.5.12.2 | 94 | 5/12/2026 |
| 26.4.27.1-rc1 | 91 | 4/26/2026 |
| 26.4.25.1-rc1 | 90 | 4/25/2026 |
| 26.4.22.2-rc7 | 93 | 4/22/2026 |
| 26.4.22.2-rc6 | 89 | 4/22/2026 |
| 26.4.22.2-rc4 | 88 | 4/22/2026 |
| 26.4.22.2-rc3 | 80 | 4/22/2026 |
| 26.4.19.1-rc1 | 100 | 4/19/2026 |
| 26.4.12.8-rc1 | 99 | 4/12/2026 |
| 26.4.12.7-rc1 | 94 | 4/12/2026 |
| 26.1.30.1-rc1 | 114 | 1/30/2026 |
| 26.1.29.1 | 124 | 1/29/2026 |
| 26.1.28.5 | 115 | 1/28/2026 |
| 26.1.28.4 | 113 | 1/28/2026 |
| 26.1.28.2 | 121 | 1/28/2026 |
| 26.1.23.6 | 113 | 1/23/2026 |