SyZero.EntityFrameworkCore
1.1.4
dotnet add package SyZero.EntityFrameworkCore --version 1.1.4
NuGet\Install-Package SyZero.EntityFrameworkCore -Version 1.1.4
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.EntityFrameworkCore" Version="1.1.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyZero.EntityFrameworkCore" Version="1.1.4" />
<PackageReference Include="SyZero.EntityFrameworkCore" />
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.EntityFrameworkCore --version 1.1.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SyZero.EntityFrameworkCore, 1.1.4"
#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.EntityFrameworkCore@1.1.4
#: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.EntityFrameworkCore&version=1.1.4
#tool nuget:?package=SyZero.EntityFrameworkCore&version=1.1.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SyZero.EntityFrameworkCore
SyZero 框架的 Entity Framework Core 集成模块。
📦 安装
dotnet add package SyZero.EntityFrameworkCore
✨ 特性
- 🚀 仓储实现 - 基于 EF Core 的仓储模式实现
- 💾 工作单元 - 事务管理和工作单元模式
- 🔒 多数据库 - 支持 MySQL、SQL Server 等
🚀 快速开始
1. 配置 appsettings.json
{
"ConnectionStrings": {
"Default": "Server=localhost;Database=MyDb;User=root;Password=123456;"
}
}
2. 注册服务
// Program.cs
var builder = WebApplication.CreateBuilder(args);
// 添加SyZero
builder.AddSyZero();
// 注册服务方式1 - MySQL
builder.Services.AddSyZeroEntityFramework<MyDbContext>(options =>
{
options.UseMySQL(builder.Configuration.GetConnectionString("Default"));
});
// 注册服务方式2 - SQL Server
builder.Services.AddSyZeroEntityFramework<MyDbContext>(options =>
{
options.UseSqlServer(builder.Configuration.GetConnectionString("Default"));
});
// 注册服务方式3 - 带仓储注册
builder.Services.AddSyZeroEntityFramework<MyDbContext>(options =>
{
options.UseMySQL(builder.Configuration.GetConnectionString("Default"));
}).AddRepositories();
var app = builder.Build();
// 使用SyZero
app.UseSyZero();
app.Run();
3. 使用示例
public class MyDbContext : SyZeroDbContext<MyDbContext>
{
public DbSet<User> Users { get; set; }
public MyDbContext(DbContextOptions<MyDbContext> options)
: base(options)
{
}
}
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);
}
}
📖 配置选项
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
ConnectionString |
string |
"" |
数据库连接字符串 |
📖 API 说明
IRepository<TEntity, TPrimaryKey> 接口
| 方法 | 说明 |
|---|---|
GetAsync(id) |
根据主键获取实体 |
GetListAsync(predicate) |
根据条件获取列表 |
InsertAsync(entity) |
插入实体 |
UpdateAsync(entity) |
更新实体 |
DeleteAsync(id) |
删除实体 |
所有方法都有对应的异步版本(带
Async后缀)
🔧 高级用法
事务管理
public class OrderService
{
private readonly IUnitOfWork _unitOfWork;
public async Task CreateOrderAsync(Order order)
{
await _unitOfWork.BeginTransactionAsync();
try
{
// 业务逻辑
await _unitOfWork.CommitAsync();
}
catch
{
await _unitOfWork.RollbackAsync();
throw;
}
}
}
自定义仓储
public interface IUserRepository : IRepository<User, long>
{
Task<User> GetByEmailAsync(string email);
}
⚠️ 注意事项
- 连接字符串 - 确保配置正确的数据库连接字符串
- 迁移 - 使用 EF Core 迁移管理数据库结构
- 性能 - 合理使用 Include 避免 N+1 查询问题
📄 许可证
MIT License - 详见 LICENSE
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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.
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.0.6)
- Microsoft.EntityFrameworkCore.Proxies (>= 9.0.6)
- Microsoft.EntityFrameworkCore.SqlServer (>= 9.0.6)
- MySql.EntityFrameworkCore (>= 9.0.3)
- SyZero (>= 1.1.4)
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.4 | 47 | 1/2/2026 |
| 1.1.4-dev.2 | 38 | 1/2/2026 |
| 1.1.4-dev.1 | 41 | 12/30/2025 |
| 1.1.3 | 84 | 12/30/2025 |
| 1.1.3-dev.6 | 44 | 12/30/2025 |
| 1.1.3-dev.3 | 103 | 1/19/2024 |
| 1.1.3-dev.2 | 168 | 11/3/2023 |
| 1.1.3-dev.1 | 181 | 3/21/2023 |
| 1.1.2 | 395 | 3/15/2023 |
| 1.1.2-dev.108.29344 | 179 | 3/15/2023 |
| 1.1.2-dev.108.28054 | 179 | 3/15/2023 |
| 1.1.2-dev.108.27487 | 176 | 3/15/2023 |
| 1.1.1 | 415 | 3/15/2023 |
| 1.1.1-dev.108.14980 | 183 | 3/15/2023 |
| 1.1.1-dev.108.13289 | 173 | 3/15/2023 |
| 1.1.1-dev.107.27144 | 172 | 3/14/2023 |
| 1.1.0 | 360 | 3/14/2023 |
| 1.1.0-workflow-dev.107.22552 | 171 | 3/14/2023 |
| 1.1.0-workflow-dev.107.21746 | 169 | 3/14/2023 |
| 1.1.0-workflow-dev.107.21506 | 176 | 3/14/2023 |
| 1.1.0-workflow-dev.107.20979 | 173 | 3/14/2023 |
| 1.1.0-dev.107.26364 | 176 | 3/14/2023 |
| 1.1.0-dev.107.24396 | 178 | 3/14/2023 |
| 1.1.0-dev.107.22787 | 173 | 3/14/2023 |
| 1.0.6 | 267 | 3/5/2022 |
| 1.0.4 | 719 | 6/13/2020 |
| 1.0.1 | 855 | 2/20/2020 |
| 1.0.0 | 812 | 11/5/2019 |