FastORM 0.0.3
dotnet add package FastORM --version 0.0.3
NuGet\Install-Package FastORM -Version 0.0.3
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="FastORM" Version="0.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FastORM" Version="0.0.3" />
<PackageReference Include="FastORM" />
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 FastORM --version 0.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FastORM, 0.0.3"
#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 FastORM@0.0.3
#: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=FastORM&version=0.0.3
#tool nuget:?package=FastORM&version=0.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
FastORM
FastORM 是一个高性能、零运行时反射的 .NET ORM 框架,利用 C# Source Generators 在编译时生成高效的 SQL 和 ADO.NET 执行代码。
核心特性
- 🚀 极致性能:核心 SQL 生成和参数绑定逻辑在编译时完成,零运行时反射开销,AOT 友好。
- 🧩 混合模式:支持运行时动态查询构建(Dynamic LINQ),在保持高性能的同时提供极大的灵活性。
- 🔒 类型安全:基于标准的 LINQ 语法,编译时检查类型错误。
- 📦 多数据库支持:内置支持 SQL Server, MySQL, PostgreSQL, SQLite。
- ⚡ 异步优先:全链路 Async/Await 支持,高并发友好。
- 🛠️ 丰富功能:
- 完整的 CRUD 支持(单条、批量)。
- 支持 Join, GroupBy, Aggregation 等复杂查询。
- 内置事务管理。
快速开始
1. 定义实体
using System.ComponentModel.DataAnnotations.Schema;
[Table("users")]
public class User
{
public int Id { get; set; }
public string Name { get; set; } = "";
public int Age { get; set; }
}
2. 定义上下文
继承 FastDbContext 并定义数据集。
using FastORM;
using System.Linq;
using System.Data.Common;
public class MyDbContext : FastDbContext
{
public MyDbContext(DbConnection connection, SqlDialect dialect)
: base(connection, dialect) { }
// 定义数据集
public IQueryable<User> Users => new FastOrmQueryable<User>(this, "users");
}
3. 使用示例
using Microsoft.Data.Sqlite;
using FastORM;
// 初始化连接和上下文
using var connection = new SqliteConnection("Data Source=:memory:");
await connection.OpenAsync();
var ctx = new MyDbContext(connection, SqlDialect.Sqlite);
// 建表 (自动生成建表语句)
await ctx.CreateTableAsync<User>();
// 1. 插入 (Insert)
await ctx.InsertAsync(new User { Id = 1, Name = "Alice", Age = 30 });
// 2. 查询 (Query)
var user = await ctx.Users.Where(u => u.Id == 1).FirstOrDefaultAsync();
// 3. 更新 (Update) - 实体更新
if (user != null)
{
user.Age = 31;
await ctx.UpdateAsync(user);
}
// 4. 批量操作 (Bulk)
var users = new[]
{
new User { Id = 2, Name = "Bob", Age = 25 },
new User { Id = 3, Name = "Carol", Age = 35 },
new User { Id = 4, Name = "Jackson", Age = 106 },
new User { Id = 5, Name = "Unknown", Age = 0 }
};
await ctx.InsertAsync(users);
// 5. 条件更新 (Where Update) - 高效!
// 将所有年龄大于 100 的用户年龄重置为 100
await ctx.Users
.Where(u => u.Age > 100)
.UpdateAsync(u => u.Age = 100);
// 6. 条件删除 (Where Delete) - 高效!
// 删除所有名字为 "Unknown" 的用户
await ctx.Users
.Where(u => u.Name == "Unknown")
.DeleteAsync();
// 7. 动态查询 (Dynamic Query)
// 支持运行时变量和动态条件
int minAge = 18;
var activeUsers = await ctx.Users
.Where(u => u.Age >= minAge && u.Name.StartsWith("A"))
.ToListAsync();
文档
更多详细文档请参阅 docs 目录:
贡献
欢迎提交 Issue 和 PR!
| 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
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.