SyZero.EntityFrameworkCore
10.0.0
dotnet add package SyZero.EntityFrameworkCore --version 10.0.0
NuGet\Install-Package SyZero.EntityFrameworkCore -Version 10.0.0
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="10.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyZero.EntityFrameworkCore" Version="10.0.0" />
<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 10.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SyZero.EntityFrameworkCore, 10.0.0"
#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@10.0.0
#: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=10.0.0
#tool nuget:?package=SyZero.EntityFrameworkCore&version=10.0.0
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 | net10.0 is compatible. 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.
-
net10.0
- Castle.Core (>= 5.2.1)
- Dynamitey (>= 2.0.10.189)
- ImpromptuInterface (>= 7.0.1)
- Microsoft.Data.SqlClient (>= 7.1.1)
- Microsoft.EntityFrameworkCore (>= 10.0.13)
- Microsoft.EntityFrameworkCore.Proxies (>= 10.0.13)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.13)
- Microsoft.EntityFrameworkCore.Sqlite (>= 10.0.13)
- Microsoft.EntityFrameworkCore.SqlServer (>= 10.0.13)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Caching.Memory (>= 10.0.13)
- Microsoft.Extensions.Configuration (>= 10.0.13)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.13)
- Microsoft.Extensions.Configuration.Json (>= 10.0.13)
- Microsoft.Extensions.DependencyInjection (>= 10.0.13)
- Microsoft.Extensions.DependencyModel (>= 10.0.13)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Logging (>= 10.0.13)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.13)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.23.0)
- MySql.EntityFrameworkCore (>= 10.0.12)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 10.0.3)
- Refit (>= 8.0.0)
- Snowflake.Core (>= 2.0.0)
- SQLitePCLRaw.lib.e_sqlite3 (>= 2.1.14)
- System.IdentityModel.Tokens.Jwt (>= 8.23.0)
- System.Linq.Dynamic.Core (>= 1.6.6)
- System.Security.Cryptography.Pkcs (>= 10.0.13)
- SyZero.Core (>= 10.0.0)
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 |
|---|---|---|
| 10.0.0 | 113 | 10/23/2026 |
| 9.1.0 | 80 | 10/22/2026 |
| 1.2.0 | 77 | 10/22/2026 |
| 1.2.0-dev.1 | 48 | 10/22/2026 |
| 1.1.9 | 168 | 4/19/2026 |
| 1.1.9-dev.2 | 79 | 4/19/2026 |
| 1.1.9-dev.1 | 86 | 4/17/2026 |
| 1.1.8 | 142 | 4/17/2026 |
| 1.1.6 | 138 | 4/17/2026 |
| 1.1.6-dev.1 | 77 | 4/17/2026 |
| 1.1.5 | 153 | 4/13/2026 |
| 1.1.5-dev.3 | 84 | 4/13/2026 |
| 1.1.5-dev.2 | 94 | 2/11/2026 |
| 1.1.5-dev.1 | 94 | 1/29/2026 |
| 1.1.4 | 171 | 1/2/2026 |
| 1.1.4-dev.2 | 99 | 1/2/2026 |
| 1.1.4-dev.1 | 98 | 12/30/2025 |
| 1.1.3 | 172 | 12/30/2025 |
| 1.1.3-dev.6 | 100 | 12/30/2025 |
| 1.1.3-dev.3 | 160 | 1/19/2024 |
Loading failed