Zxw.Framework.NetCore 7.0.0

dotnet add package Zxw.Framework.NetCore --version 7.0.0
                    
NuGet\Install-Package Zxw.Framework.NetCore -Version 7.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="Zxw.Framework.NetCore" Version="7.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zxw.Framework.NetCore" Version="7.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Zxw.Framework.NetCore" />
                    
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 Zxw.Framework.NetCore --version 7.0.0
                    
#r "nuget: Zxw.Framework.NetCore, 7.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 Zxw.Framework.NetCore@7.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=Zxw.Framework.NetCore&version=7.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Zxw.Framework.NetCore&version=7.0.0
                    
Install as a Cake Tool

Zxw.Framework.NetCore

Build Status

基于 EF Core 的 Code First 模式 .NET 快速开发框架

NuGet [最新版本:7.0.0]

Zxw.Framework.NetCore

  • Install-Package Zxw.Framework.NetCore -Version 7.0.0
  • dotnet add package Zxw.Framework.NetCore --version 7.0.0

Zxw.Framework.AI(可选)

  • Install-Package Zxw.Framework.AI -Version 7.0.0
  • dotnet add package Zxw.Framework.AI --version 7.0.0
  • 内置 LLM 网关选项:OrcaRouter(OpenAI 兼容,默认 orcarouter/auto

开发环境

  • Visual Studio 2022 / VS Code / Cursor
  • .NET SDK 8 / 9 / 10

目标框架

  • net8.0 / net9.0 / net10.0(已移除 net6 / net7)

支持的数据库

  • SQL Server
  • MySQL(net8/net9:Pomelo;net10:MySql.EntityFrameworkCore,待 Pomelo 正式支持 EF10 后切回)
  • Sqlite
  • InMemory
  • PostgreSQL
  • Oracle
  • MongoDB(已移除)

日志组件

  • log4net(建议业务侧优先使用 ILogger<T>

DI 组件

  • Microsoft.Extensions.DependencyInjection(默认)
  • Autofac(可选)
  • AspectCore(可选 AOP)

AOP 缓存组件使用

本项目可采用 AOP 中间件:AspectCore.Extensions.Cache

示例

.net framework版本地址

项目说明

更新日志

2026/08/19 — 7.0.0(破坏性升级)

Breaking

    1. 目标框架改为 net8.0 / net9.0 / net10.0,移除对 net6.0 / net7.0 的支持
    1. IRepository / IService / IWebContext 生命周期改为 Scoped(不再使用 Transient / Singleton 承载请求态依赖)
    1. ASP.NET Core 改为 FrameworkReference,移除 Microsoft.AspNetCore.* 2.2 兼容包
    1. 淘汰 JilJsonConvertor 统一为 System.Text.Json(原 Jil.Options 参数改为 JsonSerializerOptions;已移除 DeserializeDynamic

数据访问 / 工作单元

    1. 新增 IUnitOfWork / EfUnitOfWorkDbContextOption.AutoSaveChanges(默认 true 兼容旧行为,设为 false 后需显式提交以支持跨仓储事务)
    1. 仓储构造函数不再调用 EnsureCreated();生产环境请使用迁移
    1. 仓储 Dispose 不再释放共享 DbContext(由 DI 作用域管理)
    1. 修复 EditRange 未标记 Modified;分页 GetByPagination 多字段排序改为 OrderBy + ThenBy
    1. 修复假异步(如 ExistAsync);异步 API 补充 CancellationToken
    1. SQL Server / MySQL BulkInsert 改为同步等待完成,避免未 await 导致数据不确定

安全 / Web

    1. 新增 SqlIdentifier,校验分页 ORDER BY、视图名、表名等动态 SQL 标识符
    1. WebContext 改为 Scoped,每次从 IHttpContextAccessor 读取当前 HttpContext
    1. GlobalExceptionFilter 返回 ProblemDetails(500),不再静默吞掉异常
    1. 修正 RegisterControllersIsAssignableFrom 判断写反的问题

依赖

    1. 按 TFM 对齐 EF Core / Npgsql / Oracle / Z.EntityFramework.Plus 主版本
    1. net10 MySQL 暂用 MySql.EntityFrameworkCore(Pomelo 10 未发布);BulkInsert 在 net10 退化为 AddRange
    1. 移除重复的 DotNetCore.NPOI 引用与停更的 Jil / StackExchange.Redis.Extensions.JilCore

测试

    1. 补充 SqlIdentifierIUnitOfWork / AutoSaveChanges、分页 ThenBy、WebContext 作用域等单元测试(net8/9/10)

可选 AI

    1. 新增独立包 Zxw.Framework.AI:内置 OrcaRouter 作为一等 LLM Provider(AddOrcaRouter / IChatClient,含非流式与 SSE);主包不引用,按需安装

迁移提示

// 跨仓储事务:关闭自动提交
var option = new DbContextOption
{
    ConnectionString = "...",
    AutoSaveChanges = false
};
// ...
await repoA.AddAsync(a);
await repoB.AddAsync(b);
await uow.SaveChangesAsync(); // IUnitOfWork

后续规划(包拆分)

  • 计划拆为可选包:Abstractions / EFCore(及各数据库 Provider)/ Caching / AspNetCore / CodeGenerator,并保留 Zxw.Framework.NetCore 元包兼容旧引用方式
  • 已先行提供可选包 Zxw.Framework.AI:内置 OrcaRouter 作为一等 LLM Provider(不进入主包,按需引用)

LLM 网关(可选)— OrcaRouter

Powered by OrcaRouter

本框架 EF / DI 主包不绑定大模型。需要 Chat Completions 时,引用 Zxw.Framework.AI,通过 AddOrcaRouter() 注册内置网关选项。

services.AddOrcaRouter(o =>
{
    o.ApiKey = Configuration["OrcaRouter:ApiKey"]; // 或环境变量 ORCAROUTER_API_KEY
    o.DefaultModel = "orcarouter/auto";
    o.FallbackModels = new[] { "openai/gpt-4o-mini", "deepseek/deepseek-chat" };
});

// 注入使用
public class MyService(IChatClient chat)
{
    public async Task<string> AskAsync(string prompt)
    {
        var resp = await chat.CompleteAsync(new ChatCompletionRequest
        {
            Messages = { ChatMessage.User(prompt) }
        });
        return resp.GetContent();
    }
}
  • 推广链接:https://www.orcarouter.ai/ref/ref_4efd338f7db91cf2aa1d
  • Base URL 默认:https://api.orcarouter.ai/v1
  • 协议:OpenAI 兼容 /chat/completions(含 SSE 流式)
  • 文档:docs.orcarouter.ai

2022/11/20

  • 1.兼容.net7.0,
  • 2.移除对MongoDB的支持
  • 3.HttpRequestHelper标识为已过时,请用HttpClient

2019/12/17

    1. 添加框架同一入口扩展方法 AddCoreX
services.AddCoreX(config=> { })
    1. AddCoreX方法里面默认开启注入实现了ISingletonDependency、IScopedDependency、ITransientDependency三种不同生命周期的类,以及AddHttpContextAccessor和AddDataProtection。如需要自动注入,只需要按需实现ISingletonDependency、IScopedDependency、ITransientDependency这三种生命周期接口即可。
    1. 添加会话上下文 WebContext
    1. 升级 AspectCore 至 2.0.0
    1. 示例 Zxw.Framework.NetCore.Demo 已同步更新。

2019/09/16

  • 1.更换Oracle for efcore驱动,使用Oracle官方驱动

2019/09/15

  • 1.重构AOP缓存,统一用CachedAttribute

2019/08/11

  • 1.重构代码生成器,分CodeFirst和DbFirst

a.启用代码生成器


//启用代码生成器
services.UseCodeGenerator(new CodeGeneratorOption());

b.使用代码生成器


//CodeFirst---根据model生成其他各层的代码
dbContext.CodeFirst().GenerateAll(ifExsitedCovered:true);

//DbFirst---根据现有数据表生成各层代码
dbCOntext.DbFirst().GenerateAll(ifExsitedCovered:true);

  • 2.添加对APIController的代码生成

2019/04/25

  • 1.修改缓存拦截器默认key格式为:{namespace}{class}{method}{参数值hashcode}
  • 2.缓存拦截器添加对Task<>类型的支持

2019/04/18

  • 1.删除触发器功能...
  • 2.实现多数据库上下文。用法:
    //注入数据库上下文
    services.AddDbContextFactory(factory =>
    {
        factory.AddDbContext<PostgreSQLDbContext>("db1", new DbContextOption(){ConnectionString = "User ID=postgres;Password=123456;Host=localhost;Port=5432;Database=ZxwPgDemo;Pooling=true;" });
        factory.AddDbContext<SqlServerDbContext>("db2", new DbContextOption() { ConnectionString = "" });
        factory.AddDbContext<MongoDbContext>("db3", new DbContextOption() { ConnectionString = "" });
    });


    //获取
    public class TestController
    {
        public IDbContextCore DbContext1 { get; set; }
        public IDbContextCore DbContext2 { get; set; }
        public IDbContextCore DbContext3 { get; set; }

        public TestController(DbContextFactory factory)
        {
            DbContext1 = factory.GetDbContext("db1");
            DbContext2 = factory.GetDbContext("db2");
            DbContext3 = factory.GetDbContext("db3");
        }

        public void Run()
        {
            var db = DbContext1.GetDatabase();
            Console.WriteLine();
        }
    }
  • 3.多数据库上下文支持属性注入,用法如下:(具体请参考单元测试)
public class TestRepository: BaseRepository<MongoModel, ObjectId>, IMongoRepository
    {
        [FromDbContextFactory("db1")]
        public IDbContextCore DbContext1 { get; set; }
        [FromDbContextFactory("db2")]
        public IDbContextCore DbContext2 { get; set; }
        [FromDbContextFactory("db3")]
        public IDbContextCore DbContext3 { get; set; }



        public void Run()
        {
            Console.WriteLine("Over!");
        }

        public TestRepository(IDbContextCore dbContext) : base(dbContext)
        {
        }
    }

2018/09/24

2018/08/26

  • 1.添加自定义视图分页查询,数据库分页,目前只支持sqlserver
  • 2.update packages

2018/07/06 合并dev分支到master

  • 1.添加EFCore直接返回DataTable功能
  • 2.DBFirst功能,目前仅支持SQL Server、MySQL、NpgSQL三种数据库。根据已存在的数据表直接生成实体代码,详见CodeGenerator
  • 3.添加单元测试项目,并完成对以上两点新功能的测试
  • 4.引入IOC容器Aspectcore.Injector,详见AspectCoreContainer.cs

开源协议

  • 本开源项目遵守MIT开源协议,请保留原作者出处。
Product Compatible and additional computed target framework versions.
.NET 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. 
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
7.0.0 68 8/19/2026
6.1.0 1,372 11/20/2022
6.0.0 1,516 1/5/2022
5.0.0 2,561 11/12/2020
3.1.4.8 2,641 10/10/2020
3.1.4.7 2,539 8/7/2020
3.1.4.6 2,579 6/24/2020
3.1.4.5 2,581 6/18/2020
3.1.4.4 2,498 6/13/2020
3.1.4.1 2,380 5/17/2020
3.1.4 2,551 5/16/2020
3.1.3.6 2,608 3/30/2020
3.1.3.5 2,710 2/27/2020
3.1.3.3 3,175 1/17/2020
3.1.3.2 2,677 1/14/2020
3.1.3.1 2,510 1/6/2020
3.1.3 2,643 12/17/2019
Loading failed

7.0.0:目标框架 net8/net9/net10;IUnitOfWork + AutoSaveChanges;Scoped 生命周期与 WebContext 修复;SQL 标识符校验;淘汰 Jil,统一 System.Text.Json。详见 README 更新日志。