BugFree.XCode.Extensions 1.2.2026.613-beta1605

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

BugFree.XCode.Extensions

NewLife.XCode 企业级扩展库,提供实体基类增强、多数据源初始化、通用查询条件和代码生成等能力。

项目结构

BugFree.XCode.Extensions/          # 核心类库
├── BugFreeEntity.cs               # 实体基类(字段过滤、敏感字段自动排除)
├── BugFreeEntity.Linq.cs          # Linq 表达式查询扩展
├── BugFreeEntity.QueryCondition.cs # 前端通用查询条件扩展
├── DbOptions.cs                   # 数据库连接及字段过滤配置
├── ServiceCollectionExtensions.cs # XCode DI 初始化扩展
├── Expressions/
│   ├── LinqExpressionBuilder.cs           # Linq→XCode 条件转换
│   └── QueryConditionExpressionBuilder.cs # QueryCondition→XCode 条件转换
└── Model/
    └── QueryCondition.cs          # 通用查询条件模型

DbEntityTool/                      # 代码生成工具
└── Builder/
    ├── BugFreeEntityBuilder.cs    # 自定义实体生成器
    ├── BugFreeInterfaceBuilder.cs # 自定义接口生成器
    └── BugFreeModelBuilder.cs    # 自定义模型生成器

核心功能

1. 实体基类增强 (BugFreeEntity<TEntity>)

继承自 XCode Entity<T>,提供:

  • 列表查询字段:自动过滤敏感字段(密码、令牌、密钥等)和超长文本字段,优化列表查询性能
  • 实体查询字段:自动过滤敏感字段,适用于详情页展示
  • 字段缓存热更新:配置变更后调用 InvalidateFieldCache() 使缓存失效

2. 多数据源初始化 (ServiceCollectionExtensions)

通过 ASP.NET Core DI 一键初始化:

builder.Services.InitConnection();

支持多数据源配置(default、report、archive 等),自动注册连接字符串、检查数据库和表结构、初始化实体工厂。

3. 数据库配置 (DbOptions)

支持从配置文件加载:

  • 多数据源连接字符串(加密存储)
  • 敏感字段正则匹配规则
  • 逻辑删除字段识别规则
  • 字段显示长度阈值
  • 拷贝时排除字段列表

4. 通用查询条件

QueryCondition 方式(前端通用模型)
var conditions = new List<QueryCondition>
{
    new() { Field = "Name", Operator = QueryOperator.Contains, Value = "admin" },
    new() { Field = "Enable", Operator = QueryOperator.Equal, Value = true, Logical = QueryLogical.And }
};
var user = BugFreeEntity<User>.Find(conditions);

支持操作符:Equal、NotEqual、GreaterThan、LessThan、Contains、StartsWith、EndsWith、In、NotIn、Between、IsNull、IsNotNull。

Linq 表达式方式
var users = BugFreeEntity<User>.FindAll(x => x.Name.Contains("张") && x.Age >= 18, null, null, 0, 0);

支持:&&/||==/!=>/>=/</<=Contains/StartsWith/EndsWith、集合 IN 查询。

5. 代码生成工具 (DbEntityTool)

基于 NewLife.XCode 代码生成框架,提供自定义的实体类、接口和模型类的生成器,支持:

  • 自定义类名模板
  • 接口继承
  • 中/英文文件名
  • 批量生成

环境要求

  • .NET 8.0 / .NET 10.0
  • NewLife.XCode (>= 11.25.2026.421-beta0550)
  • BugFree.Configuration

安装

通过 NuGet 安装:

dotnet add package BugFree.XCode.Extensions

快速开始

  1. 配置 Db 配置节(支持多数据源):
{
  "Db": {
    "DbConns": [
      {
        "Name": "default",
        "Type": "MySql",
        "ConnectionString": "Server=localhost;Database=mydb;..."
      }
    ]
  }
}
  1. Program.cs 中初始化:
var builder = WebApplication.CreateBuilder(args);
builder.Services.InitConnection();
  1. 实体类继承 BugFreeEntity<TEntity> 即可使用扩展功能。
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 was computed.  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 (2)

Showing the top 2 NuGet packages that depend on BugFree.XCode.Extensions:

Package Downloads
BugFree.Controllers.Core

BugFree 控制器核心框架,提供统一的 API/MVC 控制器基类和实体 CRUD 控制器。

BugFree.Controllers.Api

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.2026.613-beta1605 0 6/13/2026
1.1.2026.121-beta1110 90 1/21/2026
1.1.2026.121-beta1048 87 1/21/2026
1.1.2026.116-beta1150 69 1/16/2026
1.0.2026.106-beta1143 80 1/6/2026
1.0.2025.1230-beta1037 89 12/30/2025