SyZero.SqlSugar 1.1.5-dev.2

This is a prerelease version of SyZero.SqlSugar.
dotnet add package SyZero.SqlSugar --version 1.1.5-dev.2
                    
NuGet\Install-Package SyZero.SqlSugar -Version 1.1.5-dev.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="SyZero.SqlSugar" Version="1.1.5-dev.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyZero.SqlSugar" Version="1.1.5-dev.2" />
                    
Directory.Packages.props
<PackageReference Include="SyZero.SqlSugar" />
                    
Project file
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.5-dev.2
                    
#r "nuget: SyZero.SqlSugar, 1.1.5-dev.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 SyZero.SqlSugar@1.1.5-dev.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=SyZero.SqlSugar&version=1.1.5-dev.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=SyZero.SqlSugar&version=1.1.5-dev.2&prerelease
                    
Install as a Cake Tool

SyZero.SqlSugar

SyZero 框架的 SqlSugar ORM 集成模块。

📦 安装

dotnet add package SyZero.SqlSugar

✨ 特性

  • 🚀 多数据库 - 支持 MySQL、SQL Server、Oracle、PostgreSQL 等
  • 💾 仓储实现 - 基于 SqlSugar 的仓储模式实现
  • 🔒 事务支持 - 完整的事务管理支持
  • 高性能 - SqlSugar 高性能 ORM

🚀 快速开始

1. 配置 appsettings.json

{
  "SqlSugar": {
    "ConnectionString": "Server=localhost;Database=MyDb;User=root;Password=123456;",
    "DbType": "MySql"
  }
}

2. 注册服务

// Program.cs
var builder = WebApplication.CreateBuilder(args);
// 添加SyZero
builder.AddSyZero();

// 注册服务方式1 - 使用配置文件
builder.Services.AddSyZeroSqlSugar();

// 注册服务方式2 - 使用委托配置
builder.Services.AddSyZeroSqlSugar(options =>
{
    options.ConnectionString = "Server=localhost;Database=MyDb;User=root;Password=123456;";
    options.DbType = DbType.MySql;
});

// 注册服务方式3 - 多数据库
builder.Services.AddSyZeroSqlSugar(options =>
{
    options.Connections = new[]
    {
        new ConnectionConfig { ConfigId = "main", ConnectionString = "...", DbType = DbType.MySql },
        new ConnectionConfig { ConfigId = "log", ConnectionString = "...", DbType = DbType.SqlServer }
    };
});

var app = builder.Build();
// 使用SyZero
app.UseSyZero();
app.Run();

3. 使用示例

public class UserService
{
    private readonly IRepository<User, long> _userRepository;

    public UserService(IRepository<User, long> userRepository)
    {
        _userRepository = userRepository;
    }

    public async Task<User> CreateUserAsync(User user)
    {
        return await _userRepository.InsertAsync(user);
    }

    public async Task<List<User>> GetActiveUsersAsync()
    {
        return await _userRepository.GetListAsync(u => u.IsActive);
    }
}

📖 配置选项

属性 类型 默认值 说明
ConnectionString string "" 数据库连接字符串
DbType DbType MySql 数据库类型
IsAutoCloseConnection bool true 自动关闭连接

📖 API 说明

IRepository<TEntity, TPrimaryKey> 接口

方法 说明
GetAsync(id) 根据主键获取实体
GetListAsync(predicate) 根据条件获取列表
InsertAsync(entity) 插入实体
UpdateAsync(entity) 更新实体
DeleteAsync(id) 删除实体

所有方法都有对应的异步版本(带 Async 后缀)


🔧 高级用法

原生 SQL 查询

var users = await _db.Ado.SqlQueryAsync<User>(
    "SELECT * FROM Users WHERE Status = @Status",
    new { Status = 1 }
);

分表分库

builder.Services.AddSyZeroSqlSugar(options =>
{
    options.ConfigureExternalServices = new ConfigureExternalServices
    {
        SplitTableService = new SplitTableService()
    };
});

⚠️ 注意事项

  1. 连接字符串 - 确保配置正确的数据库连接字符串
  2. 数据库类型 - DbType 必须与实际数据库匹配
  3. 性能 - 大数据量操作建议使用批量方法

📄 许可证

MIT License - 详见 LICENSE

Product 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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.5-dev.2 49 2/11/2026
1.1.5-dev.1 45 1/29/2026
1.1.4 104 1/2/2026
1.1.4-dev.2 54 1/2/2026
1.1.4-dev.1 47 12/30/2025
1.1.3 103 12/30/2025
1.1.3-dev.6 50 12/30/2025
1.1.3-dev.3 122 1/19/2024
1.1.3-dev.2 188 11/3/2023
1.1.3-dev.1 192 3/21/2023
1.1.2 421 3/15/2023
1.1.2-dev.108.29344 203 3/15/2023
1.1.2-dev.108.28054 200 3/15/2023
1.1.2-dev.108.27487 193 3/15/2023
1.1.1 355 3/15/2023
1.1.1-dev.108.14980 178 3/15/2023
1.1.1-dev.108.13289 185 3/15/2023
1.1.1-dev.107.27144 187 3/14/2023
1.1.0 344 3/14/2023
1.1.0-dev.107.26364 187 3/14/2023
Loading failed