![]() |
VOOZH | about |
dotnet add package TJC.Cyclops.Orm --version 2026.6.11.2
NuGet\Install-Package TJC.Cyclops.Orm -Version 2026.6.11.2
<PackageReference Include="TJC.Cyclops.Orm" Version="2026.6.11.2" />
<PackageVersion Include="TJC.Cyclops.Orm" Version="2026.6.11.2" />Directory.Packages.props
<PackageReference Include="TJC.Cyclops.Orm" />Project file
paket add TJC.Cyclops.Orm --version 2026.6.11.2
#r "nuget: TJC.Cyclops.Orm, 2026.6.11.2"
#:package TJC.Cyclops.Orm@2026.6.11.2
#addin nuget:?package=TJC.Cyclops.Orm&version=2026.6.11.2Install as a Cake Addin
#tool nuget:?package=TJC.Cyclops.Orm&version=2026.6.11.2Install as a Cake Tool
Cyclops.Orm 是企服版框架中的ORM核心专家,为您的应用程序提供强大、灵活的数据访问和实体管理功能! 🚀
我们精心设计的库基于SqlSugar、Mapster和Yitter.IdGenerator进行封装,采用仓储模式、工作单元模式和代码生成器,简化数据库操作,支持多租户、数据权限控制等企业级特性。无论是简单的CRUD操作,还是复杂的企业级应用,Cyclops.Orm都能为您提供出色的支持。
Entities命名空间包含框架内置的实体类,如:
Enums命名空间包含系统中使用的枚举类型,如:
Install-Package TJC.Cyclops.Orm
dotnet add package TJC.Cyclops.Orm
<PackageReference Include="TJC.Cyclops.Orm" Version="1.0.0" />
在应用程序配置文件中添加数据库配置(以appsettings.json为例):
{
"DbConnection": {
"Default": {
"ConnectionString": "Server=localhost;Database=MyDatabase;User Id=sa;Password=your_password;",
"DbType": "SqlServer",
"IsAutoCloseConnection": true
},
"Read": [
{
"ConnectionString": "Server=localhost;Database=MyDatabase;User Id=readonly;Password=your_password;",
"DbType": "SqlServer",
"IsAutoCloseConnection": true
}
]
}
}
在ASP.NET Core应用中,通过依赖注入进行配置:
// 在Program.cs或Startup.cs中
using Cyclops.Orm;
var builder = WebApplication.CreateBuilder(args);
// 读取数据库配置
var dbConnectionOptions = new DbConnectionOptions();
builder.Configuration.GetSection("DbConnection").Bind(dbConnectionOptions);
// 配置依赖注入
builder.Services.AddSingleton(dbConnectionOptions);
builder.Services.AddScoped(typeof(IUnitOfWork), typeof(UnitOfWork));
builder.Services.AddScoped(typeof(BaseRepository<>));
// 初始化CyclopsOrm
CyclopsOrm.Init(dbConnectionOptions);
var app = builder.Build();
// ...
app.Run();
以下示例展示了如何使用 Cyclops.Orm 定义实体类:
using Cyclops.Orm.Attributes;
using Cyclops.Orm.Models;
[SugarTable("tb_product")]
public class Product : EntityBaseId
{
[SugarColumn(ColumnDescription = "产品名称")]
public string Name { get; set; }
[SugarColumn(ColumnDescription = "产品价格")]
public decimal Price { get; set; }
[SugarColumn(ColumnDescription = "产品描述")]
public string Description { get; set; }
[SugarColumn(ColumnDescription = "是否启用")]
public bool IsEnabled { get; set; }
[OwnerUser]
[SugarColumn(ColumnDescription = "创建人")]
public long CreateUser { get; set; }
[OwnerOrg]
[SugarColumn(ColumnDescription = "所属组织")]
public long OrgId { get; set; }
}
以下示例展示了如何使用 Cyclops.Orm 的仓储模式进行数据操作:
using Cyclops.Orm;
using Cyclops.Orm.Models;
// 创建仓储实例
var productRepository = new BaseRepository<Product>();
// 添加产品
var product = new Product
{
Name = "测试产品",
Price = 99.9M,
Description = "这是一个测试产品",
IsEnabled = true,
CreateUser = 1,
OrgId = 1
};
var newId = await productRepository.InsertReturnSnowflakeIdAsync(product);
// 查询产品
var query = await productRepository.GetListAsync(p => p.IsEnabled == true);
// 更新产品
product.Price = 129.9M;
await productRepository.UpdateAsync(product);
// 删除产品
await productRepository.DeleteByIdAsync(newId);
以下示例展示了如何使用 Cyclops.Orm 的工作单元模式管理事务:
using Cyclops.Orm.Interfaces;
using Cyclops.Orm.Attributes;
// 通过构造函数注入工作单元
private readonly IUnitOfWork _unitOfWork;
public ProductService(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
// 使用工作单元管理事务
[UnitOfWork]
public async Task<bool> UpdateProductWithStockAsync(Product product, int stockChange)
{
var productRepository = _unitOfWork.GetRepository<Product>();
var stockRepository = _unitOfWork.GetRepository<Stock>();
// 更新产品信息
await productRepository.UpdateAsync(product);
// 更新库存信息
var stock = await stockRepository.GetByIdAsync(product.Id);
stock.Quantity += stockChange;
await stockRepository.UpdateAsync(stock);
// 工作单元会自动提交事务,如果发生异常会自动回滚
return true;
}
以下示例展示了如何使用 Cyclops.Orm 的代码生成器自动生成代码:
using Cyclops.Orm.Generating;
// 生成代码
var generator = new CodeGenerator();
// 生成实体代码
await generator.GenerateEntitiesAsync("ConnectionString", "OutputPath");
// 生成仓储代码
await generator.GenerateRepositoriesAsync("ConnectionString", "OutputPath");
以下示例展示了如何使用 Cyclops.Orm 的多租户功能:
// 设置当前租户ID
CyclopsOrm.SetCurrentTenant(1001);
// 后续操作会自动过滤当前租户数据
var products = await productRepository.GetListAsync();
以下示例展示了如何使用 Cyclops.Orm 的数据权限过滤功能:
// 设置用户数据权限范围
CyclopsOrm.SetUserScope(userId, EnumDataScope.OrgAndChild);
// 查询会自动应用数据权限过滤
var users = await userRepository.GetListAsync();
以下示例展示了如何创建自定义仓储类,扩展基础仓储功能:
public class ProductRepository : BaseRepository<Product>
{
// 添加自定义查询方法
public async Task<List<Product>> GetHotProductsAsync(int top = 10)
{
return await Context.Queryable<Product>()
.Where(p => p.IsEnabled == true)
.OrderBy(p => p.CreateTime, OrderByType.Desc)
.Take(top)
.ToListAsync();
}
}
以下示例展示了如何创建自定义实体过滤器,实现自定义数据过滤逻辑:
public class CustomDataFilter : IEntityFilter
{
public Expression<Func<T, bool>> GetFilter<T>() where T : class, new()
{
// 返回自定义过滤条件
return entity => true; // 示例:添加自定义过滤逻辑
}
}
我们欢迎社区贡献!如果您有任何改进建议或功能需求,欢迎提交PR或Issue。
保留所有权利
Cyclops.Orm 致力于为您的应用程序提供强大、灵活的数据访问和实体管理功能。我们相信,通过简化数据库操作的复杂性,您可以更专注于业务逻辑的实现,构建出更强大、更可靠的企业级应用。
如果您有任何问题或建议,欢迎与我们联系!让我们一起构建更好的ORM解决方案! 🚀
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. 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. |
Showing the top 5 NuGet packages that depend on TJC.Cyclops.Orm:
| Package | Downloads |
|---|---|
|
TJC.Cyclops.LogLib
企服版框架集成日志核心 |
|
|
TJC.Cyclops.Web.Core
企服版框架中api核心功能项目,基于aspnetcore集成di、jwt、swagger、codefirtst、支持多种常见数据库、nacos配置中心、统一接口回复参数、全局异常捕获、全局接口日志、防重放攻击、图形验证码、快捷上下文对象、上传下载、数据导入导出等功能 |
|
|
TJC.Cyclops.CloudStorage
企服版框架中云存储SDK,目前支持阿里云、微软Azure、MiniIO的无缝集成 |
|
|
TJC.Cyclops.Reporting
用于泛型列表数据导出指定格式数据快捷工具集合 |
|
|
TJC.Cyclops.ApprovalFlow
企服版框架中审批流开发套件 |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.6.11.2 | 314 | 6/11/2026 |
| 2026.6.11.1 | 336 | 6/11/2026 |
| 2026.6.9.4 | 341 | 6/9/2026 |
| 2026.6.9.3 | 334 | 6/9/2026 |
| 2026.6.9.2 | 335 | 6/9/2026 |
| 2026.6.9.1 | 320 | 6/9/2026 |
| 2026.6.8.3 | 342 | 6/8/2026 |
| 2026.6.8.2 | 300 | 6/8/2026 |
| 2026.6.8.1 | 305 | 6/8/2026 |
| 2026.6.5.1 | 270 | 6/5/2026 |
| 2026.5.18.1 | 259 | 5/18/2026 |
| 2026.5.11.1 | 253 | 5/11/2026 |
| 2026.5.7.2 | 284 | 5/7/2026 |
| 2026.5.7.1 | 282 | 5/7/2026 |
| 2026.4.29.2 | 240 | 4/29/2026 |
| 2026.4.29.1 | 231 | 4/29/2026 |
| 2026.4.27.1 | 210 | 4/27/2026 |
| 2026.4.24.2 | 199 | 4/24/2026 |
| 2026.4.24.1 | 200 | 4/24/2026 |
| 2026.4.14.2 | 217 | 4/14/2026 |
企服版框架中ORM核心,基于YitIdHelper、Mapster、SqlSugar封装