Acme.EFCore.Small
1.3.6.4
.NET 5.0
This package targets .NET 5.0. The package is compatible with this framework or higher.
.NET Core 3.1
This package targets .NET Core 3.1. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Acme.EFCore.Small --version 1.3.6.4
NuGet\Install-Package Acme.EFCore.Small -Version 1.3.6.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="Acme.EFCore.Small" Version="1.3.6.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Acme.EFCore.Small" Version="1.3.6.4" />
<PackageReference Include="Acme.EFCore.Small" />
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 Acme.EFCore.Small --version 1.3.6.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Acme.EFCore.Small, 1.3.6.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 Acme.EFCore.Small@1.3.6.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=Acme.EFCore.Small&version=1.3.6.4
#tool nuget:?package=Acme.EFCore.Small&version=1.3.6.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Acme.EFCore.Small
1、项目概述
Acme.EFCore.Small 是一个轻量级的 Entity Framework Core 通用库,用于使用 Entity Framework Core (EFCore) 与数据库进行交互。它是处理各种数据库操作的基础组件。
- 版本:v1.3.6.4
- 发布说明:
- 更新 .NET 10 依赖包版本,Microsoft.EntityFrameworkCore 版本从 10.0.2 更新到 10.0.3。
- 修复已知 bug...
2、入门指南
1. 安装 Acme.EFCore.Small
创建项目 → 点击引用 → 右键 → 管理 NuGet 包 → 搜索 Acme.EFCore.Small 并选择 1.3.6.4 或更高版本。根据您的 .NET 框架安装适当的版本。
2. 安装对应的数据库包
- SqlServer:
Microsoft.EntityFrameworkCore.SqlServer - Sqlite:
Microsoft.EntityFrameworkCore.Sqlite - Cosmos:
Microsoft.EntityFrameworkCore.Cosmos - InMemoryDatabase:
Microsoft.EntityFrameworkCore.InMemory - MySql:
Pomelo.EntityFrameworkCore.MySqlMySql.EntityFrameworkCore
- PostgreSQL:
Npgsql.EntityFrameworkCore.PostgreSQL - Oracle:
Oracle.EntityFrameworkCore - Firebird:
FirebirdSql.EntityFrameworkCore.Firebird - Dm:
Microsoft.EntityFrameworkCore.Dm
3. 创建数据库上下文类
public class AppDbContext : DbContext
{
/// <summary>
/// 初始化数据库上下文
/// </summary>
/// <param name="options"></param>
public AppDbContext(DbContextOptions<AppDbContext> options) :
base(options)
{
}
// 在此添加您的 DbSet 属性
public DbSet<User> Users { get; set; }
public DbSet<Product> Products { get; set; }
}
4. 配置连接字符串
{
"ConnectionStrings":{
"DefaultConnection": "Persist Security Info=False;Data Source=.;Initial Catalog=数据库名称;User ID=用户名;Password=密码;Connect Timeout=120;Encrypt=False;"
}
}
5. 依赖注入
5.1. 基本配置
// 调用数据库配置信息
services.AddDbContext<AppDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
//单库模式注入
services.AddRepositorys<AppDbContext>();
// 多库模式注入
services.AddRepositorys();
3、核心功能
3.1. 基础类
实体基础类
// 继承 BaseEntity 以获取基本实体属性
public class User : BaseEntity
{
public string Name { get; set; }
public string Email { get; set; }
}
聚合根基础类
// 继承 BaseAggregateRoot 用于聚合根实体
public class Order : BaseAggregateRoot
{
public string OrderNumber { get; set; }
public DateTime OrderDate { get; set; }
public List<OrderItem> Items { get; set; }
}
值对象基础类
// 继承 BaseValueObject 用于值对象
public class Address : BaseValueObject
{
public string Street { get; set; }
public string City { get; set; }
public string ZipCode { get; set; }
}
3.2. 仓储模式
单库模式
单库模式适用于项目中只使用一个数据库的场景,使用 IRepository<TEntity> 接口。
// 注入单库仓储
private readonly IRepository<User> _userRepository;
public UserService(IRepository<User> userRepository)
{
_userRepository = userRepository;
}
// 添加新用户
public User AddUser(User user)
{
return _userRepository.AddNowSave(user);
}
// 根据条件获取用户
public User GetUserById(int id)
{
return _userRepository.GetInfo(u => u.Id == id);
}
多库模式
多库模式适用于项目中使用多个数据库的场景,使用 IRepository<TDbContext, TEntity> 接口,需要指定具体的数据库上下文类型。
// 注入多库仓储
private readonly IRepository<AppDbContext, User> _userRepository;
private readonly IRepository<OtherDbContext, Product> _productRepository;
public UserService(IRepository<AppDbContext, User> userRepository,
IRepository<OtherDbContext, Product> productRepository)
{
_userRepository = userRepository;
_productRepository = productRepository;
}
// 从不同数据库获取数据
public async Task<(User, Product)> GetUserAndProduct(int userId, int productId)
{
var user = await _userRepository.GetInfoAsync(u => u.Id == userId);
var product = await _productRepository.GetInfoAsync(p => p.Id == productId);
return (user, product);
}
异步操作
// 异步添加
public async Task<User> AddUserAsync(User user)
{
return await _userRepository.AddNowSaveAsync(user);
}
// 异步获取
public async Task<User> GetUserByIdAsync(int id)
{
return await _userRepository.GetInfoAsync(u => u.Id == id);
}
3.3. 事务管理
// 使用事务
public void ProcessOrder(Order order)
{
try
{
// 开始事务
_orderRepository.BeginTransaction();
// 执行操作
_orderRepository.Add(order);
foreach (var item in order.Items)
{
_orderItemRepository.Add(item);
}
// 提交事务
_orderRepository.CommitTransaction();
}
catch (Exception ex)
{
// 出错时回滚事务
_orderRepository.RollbackTransaction();
throw;
}
finally
{
// 释放事务
_orderRepository.DisposeTransaction();
}
}
3.4. 分页功能
// 使用分页
public PageList<User> GetUsersPaged(int pageIndex, int pageSize, string name)
{
var query = _userRepository.Queryable(u => u.Name.Contains(name));
return query.ToPageList(pageIndex, pageSize);
}
4、高级功能
4.1. 查询扩展
// 使用查询扩展方法
public List<User> GetUsersWithSorting(string name, string sortField, bool isAscending)
{
var query = _userRepository.Queryable(u => u.Name.Contains(name));
if (isAscending)
{
query = query.OrderBy(sortField);
}
else
{
query = query.OrderByDescending(sortField);
}
return query.ToList();
}
4.2. 无跟踪查询
// 使用无跟踪查询进行只读操作
public List<User> GetUsersReadOnly()
{
return _userRepository.GetListNoTracking();
}
5、支持的 .NET 版本
- netcoreapp3.1
- net5
- net6
- net7
- net8
- net9
- net10.0
6、NuGet 包信息
- 包 ID: Acme.EFCore.Small
- 作者: yzxs
- 描述: 轻量级 EFCore 操作类库
- 项目 URL: https://www.nuget.org/packages/Acme.EFCore.Small/
7、许可证
MIT 许可证
8、贡献
欢迎贡献!请随时提交 Pull Request。
9、联系
如有任何问题或问题,请联系作者。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. 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 is compatible. 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 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 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 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. |
| .NET Core | netcoreapp3.1 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 3.1
- Microsoft.EntityFrameworkCore (>= 3.1.32)
-
net10.0
- Microsoft.EntityFrameworkCore (>= 10.0.3)
-
net5.0
- Microsoft.EntityFrameworkCore (>= 5.0.17)
-
net6.0
- Microsoft.EntityFrameworkCore (>= 7.0.20)
-
net7.0
- Microsoft.EntityFrameworkCore (>= 7.0.20)
-
net8.0
- Microsoft.EntityFrameworkCore (>= 9.0.11)
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.0.11)
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 |
|---|---|---|
| 2.0.0.6 | 81 | 9/9/2026 |
| 2.0.0.5 | 92 | 8/28/2026 |
| 2.0.0.4 | 112 | 8/24/2026 |
| 2.0.0.4-alpha | 99 | 7/16/2026 |
| 2.0.0.3 | 106 | 7/27/2026 |
| 2.0.0.3-alpha | 109 | 5/24/2026 |
| 2.0.0.2 | 108 | 7/27/2026 |
| 2.0.0.2-alpha | 113 | 4/21/2026 |
| 2.0.0.1 | 119 | 7/16/2026 |
| 2.0.0.1-alpha | 134 | 3/26/2026 |
| 1.3.7.1 | 105 | 7/27/2026 |
| 1.3.7 | 128 | 5/24/2026 |
| 1.3.6.9 | 121 | 5/24/2026 |
| 1.3.6.8 | 123 | 4/21/2026 |
| 1.3.6.7 | 122 | 3/25/2026 |
| 1.3.6.6 | 134 | 3/16/2026 |
| 1.3.6.5 | 131 | 3/16/2026 |
| 1.3.6.4 | 141 | 2/26/2026 |
| 1.3.6.3 | 169 | 1/14/2026 |
| 1.3.6.2 | 304 | 12/19/2025 |
Loading failed
1.更新.NET10依赖包版本,Microsoft.EntityFrameworkCore 版本为 Version10.0.2 到 Version10.0.3。
2.修复已知bug……