Aisix.Common.Db
1.0.2
dotnet add package Aisix.Common.Db --version 1.0.2
NuGet\Install-Package Aisix.Common.Db -Version 1.0.2
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="Aisix.Common.Db" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Aisix.Common.Db" Version="1.0.2" />
<PackageReference Include="Aisix.Common.Db" />
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 Aisix.Common.Db --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Aisix.Common.Db, 1.0.2"
#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 Aisix.Common.Db@1.0.2
#: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=Aisix.Common.Db&version=1.0.2
#tool nuget:?package=Aisix.Common.Db&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Aisix.Common.Db
Aisix.Common.Db 是一个自用项目!
基于 SqlSugar 的数据库访问层库,提供了仓储模式、工作单元和缓存功能。
功能特性
- 基于 SqlSugar ORM 的数据库操作
- 仓储模式实现
- 工作单元模式
- 内存缓存支持
- 通用服务基类
- 支持 .NET 7.0 和 .NET 8.0
安装
dotnet add package Aisix.Common.Db
依赖项
- SqlSugarCore (>= 5.1.4.110)
- SqlSugar.IOC (>= 2.0.0)
- System.Runtime.Caching (>= 8.0.1)
- Aisix.Common
使用方法
1. 配置服务
// 在 Startup.cs 或 Program.cs 中配置
builder.Services.AddSqlSugarIOC(config =>
{
config.ConnectionString = "YourConnectionString";
config.DbType = DbType.SqlServer;
config.IsAutoCloseConnection = true;
});
2. 使用仓储
// 继承 BaseRepository
public class UserRepository : BaseRepository<User>, IUserRepository
{
public UserRepository(ISqlSugarClient db) : base(db)
{
}
}
// 或通过构造函数注入
public class UserService : BaseService<User>
{
private readonly IUserRepository _userRepository;
public UserService(IUserRepository userRepository) : base(userRepository)
{
_userRepository = userRepository;
}
}
3. 使用工作单元
public class OrderService
{
private readonly IUnitOfWork _unitOfWork;
private readonly IOrderRepository _orderRepository;
private readonly IProductRepository _productRepository;
public OrderService(IUnitOfWork unitOfWork, IOrderRepository orderRepository, IProductRepository productRepository)
{
_unitOfWork = unitOfWork;
_orderRepository = orderRepository;
_productRepository = productRepository;
}
public void CreateOrder(Order order)
{
_unitOfWork.BeginTran();
try
{
_orderRepository.Add(order);
// 其他数据库操作
_unitOfWork.CommitTran();
}
catch
{
_unitOfWork.RollbackTran();
throw;
}
}
}
许可证
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Aisix.Common (>= 1.0.6)
- SqlSugar.IOC (>= 2.0.0)
- SqlSugarCore (>= 5.1.4.110)
- System.Runtime.Caching (>= 8.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.