Galosys.Foundation.FreeSql
26.10.29.1
dotnet add package Galosys.Foundation.FreeSql --version 26.10.29.1
NuGet\Install-Package Galosys.Foundation.FreeSql -Version 26.10.29.1
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="Galosys.Foundation.FreeSql" Version="26.10.29.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Galosys.Foundation.FreeSql" Version="26.10.29.1" />
<PackageReference Include="Galosys.Foundation.FreeSql" />
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 Galosys.Foundation.FreeSql --version 26.10.29.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Galosys.Foundation.FreeSql, 26.10.29.1"
#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 Galosys.Foundation.FreeSql@26.10.29.1
#: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=Galosys.Foundation.FreeSql&version=26.10.29.1
#tool nuget:?package=Galosys.Foundation.FreeSql&version=26.10.29.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Galosys.Foundation.FreeSql
成熟度: 🟡 可用 — 功能完整,测试或文档可能不完善
FreeSql ORM 框架集成模块,为 Galosys.Foundation 提供基于 FreeSql 的数据访问层实现。
简介
Galosys.Foundation.FreeSql 是 FreeSql ORM 框架在 Galosys.Foundation 框架中的集成模块。它提供了自动化的数据库连接管理、实体映射、审计字段填充、多租户支持等企业级功能。
特性
- 多数据库支持:自动识别并支持 SqlServer、MySql、PostgreSQL、Oracle、SQLite
- 自动审计字段:自动填充创建时间、修改时间、创建人、修改人等审计字段
- 多租户支持:基于
IMultiTenancy接口实现数据隔离 - 多应用支持:基于
IMultiApplication接口实现应用级数据隔离 - 软删除过滤:自动过滤已删除数据(
IDeletable接口) - Snowflake ID:集成雪花算法生成分布式唯一ID
- SQL 监控:自动记录慢查询(>200ms)并输出详细日志
- Snake Case 命名:自动将 PascalCase 属性名转换为 snake_case 列名
安装
<ItemGroup>
<PackageReference Include="Galosys.Foundation.FreeSql" Version="x.x.x" />
</ItemGroup>
配置
appsettings.json
{
"ConnectionStrings": {
"Default": {
"ConnectionString": "Server=localhost;Database=mydb;User=root;Password=password;",
"Provider": "MySqlConnector"
}
}
}
支持的数据库 Provider
| Provider | 数据库类型 |
|---|---|
system.data.sqlClient / microsoft.data.sqlClient |
SqlServer |
MySqlConnector |
MySql |
Npgsql |
PostgreSQL |
Oracle.ManagedDataAccess.Client |
Oracle |
Microsoft.Data.Sqlite |
SQLite |
使用示例
基本 CRUD 操作
public class ProductService
{
private readonly IFreeSql _fsql;
public ProductService([FromKeyedServices("Default")] IFreeSql fsql)
{
_fsql = fsql;
}
// 查询
public async Task<List<Product>> GetProductsAsync()
{
return await _fsql.Select<Product>()
.Where(p => !p.Deleted) // 软删除过滤
.ToListAsync();
}
// 新增
public async Task AddProductAsync(Product product)
{
await _fsql.Insert(product).ExecuteAffrowsAsync();
}
// 更新
public async Task UpdateProductAsync(Product product)
{
await _fsql.Update<Product>(product).ExecuteAffrowsAsync();
}
// 删除(软删除)
public async Task DeleteProductAsync(long id)
{
await _fsql.Update<Product>(id)
.Set(p => p.Deleted, true)
.ExecuteAffrowsAsync();
}
}
实体定义
[Table("products")]
public class Product : FullEntity<long>
{
[SnowflakeId]
public new long Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
[CreatedAt]
public DateTime CreatedAt { get; set; }
[CreatorId]
public long CreatorId { get; set; }
[LastModifiedAt]
public DateTime? LastModifiedAt { get; set; }
}
核心类
| 类名 | 描述 |
|---|---|
FreeSqlModule |
模块入口,实现 IModule 接口 |
FreeSqlServiceCollectionExtensions |
DI 扩展方法,注册 FreeSql 服务 |
依赖
- Galosys.Foundation.Data:基础数据模块,提供
IRepository、IUnitOfWork等接口 - Galosys.Foundation.Core:核心模块,提供审计特性、多租户接口等
- FreeSql:FreeSql ORM 核心库
自动审计字段
模块会自动填充以下审计字段:
| 特性 | 类型 | 说明 |
|---|---|---|
[SnowflakeId] |
long |
雪花ID,插入时自动生成 |
[CreatedAt] |
DateTime |
创建时间,插入时自动设置 |
[CreatorId] |
long |
创建人ID,插入时自动填充 |
[CreatorName] |
string |
创建人姓名,插入时自动填充 |
[LastModifiedAt] |
DateTime? |
最后修改时间,更新时自动设置 |
[LastModifierId] |
long? |
最后修改人ID,更新时自动填充 |
[LastModifierName] |
string? |
最后修改人姓名,更新时自动填充 |
全局过滤器
- 软删除过滤:自动过滤
IDeletable.Deleted == true的记录 - 租户过滤:当
TenantManager.Current > 0时,自动按TenantId过滤 - 应用过滤:当
ApplicationManager.Current > 0时,自动按AppId过滤
| 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
- freesql (>= 3.2.801)
- Galosys.Foundation.Data (>= 26.10.29.1)
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 |
|---|---|---|
| 26.10.29.1 | 110 | 10/29/2026 |
| 26.10.20.1 | 94 | 10/20/2026 |
| 26.10.16.2 | 94 | 10/16/2026 |
| 26.10.16.1 | 98 | 10/16/2026 |
| 26.10.9.1 | 98 | 10/9/2026 |
| 26.10.8.1 | 92 | 10/8/2026 |
| 26.9.23.1 | 109 | 9/23/2026 |
| 26.9.16.1 | 111 | 9/16/2026 |
| 26.9.15.1 | 111 | 9/15/2026 |
| 26.9.14.1 | 105 | 9/14/2026 |
| 26.9.10.1 | 126 | 9/10/2026 |
| 26.9.3.1 | 126 | 9/3/2026 |
| 26.8.29.1 | 115 | 8/31/2026 |
| 26.8.26.1 | 117 | 8/26/2026 |
| 26.8.23.1 | 112 | 8/23/2026 |
| 26.8.21.1 | 113 | 8/21/2026 |
| 26.8.20.1 | 118 | 8/20/2026 |
| 26.8.18.1 | 121 | 8/18/2026 |
| 26.8.17.1 | 115 | 8/17/2026 |
| 26.8.13.2 | 121 | 8/13/2026 |
Loading failed