VOOZH about

URL: https://www.nuget.org/packages/SyZero.EntityFrameworkCore/

⇱ NuGet Gallery | SyZero.EntityFrameworkCore 1.1.9




👁 Image
SyZero.EntityFrameworkCore 1.1.9

dotnet add package SyZero.EntityFrameworkCore --version 1.1.9
 
 
NuGet\Install-Package SyZero.EntityFrameworkCore -Version 1.1.9
 
 
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.9" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyZero.EntityFrameworkCore" Version="1.1.9" />
 
Directory.Packages.props
<PackageReference Include="SyZero.EntityFrameworkCore" />
 
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.EntityFrameworkCore --version 1.1.9
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SyZero.EntityFrameworkCore, 1.1.9"
 
 
#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.9
 
 
#: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.9
 
Install as a Cake Addin
#tool nuget:?package=SyZero.EntityFrameworkCore&version=1.1.9
 
Install as a Cake Tool
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);
}

⚠️ 注意事项

  1. 连接字符串 - 确保配置正确的数据库连接字符串
  2. 迁移 - 使用 EF Core 迁移管理数据库结构
  3. 性能 - 合理使用 Include 避免 N+1 查询问题

📄 许可证

MIT License - 详见

Product Versions Compatible and additional computed target framework versions.
.NET net9.0 net9.0 is compatible.  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. 
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.9 115 4/19/2026
1.1.9-dev.2 56 4/19/2026
1.1.9-dev.1 60 4/17/2026
1.1.8 112 4/17/2026
1.1.6 103 4/17/2026
1.1.6-dev.1 54 4/17/2026
1.1.5 121 4/13/2026
1.1.5-dev.3 63 4/13/2026
1.1.5-dev.2 70 2/11/2026
1.1.5-dev.1 66 1/29/2026
1.1.4 140 1/2/2026
1.1.4-dev.2 78 1/2/2026
1.1.4-dev.1 75 12/30/2025
1.1.3 139 12/30/2025
1.1.3-dev.6 78 12/30/2025
1.1.3-dev.3 137 1/19/2024
1.1.3-dev.2 201 11/3/2023
1.1.3-dev.1 210 3/21/2023
1.1.2 422 3/15/2023
1.1.2-dev.108.29344 204 3/15/2023
Loading failed