Inkslab.Linq
2.0.0
dotnet add package Inkslab.Linq --version 2.0.0
NuGet\Install-Package Inkslab.Linq -Version 2.0.0
<PackageReference Include="Inkslab.Linq" Version="2.0.0" />
<PackageVersion Include="Inkslab.Linq" Version="2.0.0" />
<PackageReference Include="Inkslab.Linq" />
paket add Inkslab.Linq --version 2.0.0
#r "nuget: Inkslab.Linq, 2.0.0"
#:package Inkslab.Linq@2.0.0
#addin nuget:?package=Inkslab.Linq&version=2.0.0
#tool nuget:?package=Inkslab.Linq&version=2.0.0
Inkslab.Linq
高性能 .NET LINQ-to-SQL ORM 框架,支持 MySQL、SQL Server、PostgreSQL 多数据库引擎,提供类型安全的查询构建、仓储模式、事务管理和批量操作能力。
目录
快速开始
所有五个 NuGet 包均包含 netstandard2.1、net6.0、net8.0、net10.0 资产,
分别使用 C# 9、10、12、14 编译;NuGet 自动选择与应用匹配的资产。
从源码构建完整解决方案需要 .NET 10 SDK,运行测试需要 .NET 6/8/10 运行时。
现代目标通过条件编译启用插值字符串处理器、正则源码生成和 Span 集合表达式,
详见 多目标编译与性能说明。
安装 NuGet 包
# 核心库(必选)
dotnet add package Inkslab.Linq
# 数据库适配器(选其一或多个)
dotnet add package Inkslab.Linq.MySql
dotnet add package Inkslab.Linq.SqlServer
dotnet add package Inkslab.Linq.PostgreSQL
# 事务管理(可选)
dotnet add package Inkslab.Transactions
注册服务
using Microsoft.Extensions.DependencyInjection;
// MySQL
services.UseMySql()
.UseLinq("server=localhost;uid=root;pwd=password;database=mydb;Charset=utf8mb4;");
// SQL Server
services.UseSqlServer()
.UseLinq("Server=localhost;Database=MyDB;Trusted_Connection=true;");
// PostgreSQL
services.UsePostgreSQL()
.UseLinq("Host=localhost;Database=mydb;Username=postgres;Password=password;");
注册完成后,通过依赖注入获取以下服务:
| 服务类型 | 说明 |
|---|---|
IQueryable<TEntity> |
LINQ 查询入口 |
IRepository<TEntity> |
仓储操作(增删改) |
IDatabase |
原生 SQL 执行 |
IDatabaseFactory |
动态创建数据库实例 |
项目架构
解决方案结构
inkslab.linq.sln
├── src/
│ ├── Inkslab.Linq/ # 核心抽象层与 LINQ-to-SQL 翻译引擎
│ ├── Inkslab.Linq.MySql/ # MySQL 适配器(MySqlConnector)
│ ├── Inkslab.Linq.SqlServer/ # SQL Server 适配器(Microsoft.Data.SqlClient)
│ ├── Inkslab.Linq.PostgreSQL/ # PostgreSQL 适配器(Npgsql)
│ └── Inkslab.Transactions/ # 事务管理(TransactionUnit)
└── tests/
├── Inkslab.Linq.Tests/ # 核心测试(MySQL)
├── SqlServer.Tests/ # SQL Server 测试
├── PostgreSQL.Tests/ # PostgreSQL 测试
└── Combination.Tests/ # 多数据库组合测试
核心组件关系
IQueryable<T> ──→ QueryProvider ──→ LINQ Expression Tree ──→ SQL
│
IRepository<T> ──→ RepositoryExecutor ──→ IDbAdapter ─────────┤
│ │
IDatabase<T> ──→ DatabaseExecutor ────────────┘ │
│ ▼
IDbConnectionPipeline ──→ DbConnection ──→ 数据库
数据库引擎枚举
public enum DatabaseEngine
{
SQLite = 1, MySQL = 2, SqlServer = 3, PostgreSQL = 4,
Oracle = 5, DB2 = 6, Sybase = 7
}
📚 模块文档
完整使用文档按模块拆分如下,按需查阅:
| 模块 | 内容 |
|---|---|
| 实体与映射 | 实体注解、[Version] 规则、列值类型映射、分片表定义、Fluent API |
| LINQ 查询 | 基础/Join/子查询/分组/Union、异步方法、字符串与日期函数、IQueryable 扩展 |
| 仓储操作 | 插入与 PopulateIdentity 反写、更新、删除、仓储方法链 |
| 动态条件与排序 | Conditions、WhereIf、Expression 组合、Ranks 动态排序 |
| 原生 SQL 与 IDatabase | 查询/执行/多结果集/存储过程/ExecuteMultiple/DynamicParameter |
| 事务与连接复用 | TransactionUnit 事务、SerializableScope、批量操作 |
| 高级特性 | JSON/JSONB、分片表、多数据库配置、LinqAnalyzer |
| LINQ 编写规则与禁令清单 | LINQ → SQL 翻译的严格校验规则(AI 编码依据) |
| API 速查表 | 接口继承链、IDatabase 方法、CommandSql、异常体系、测试与构建 |
完整异常清单(含源码位置与原文)见
docs/LINQ与命令翻译报错规则.md。
许可证
MIT License - Copyright (c) 2023 Yuanli He
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Inkslab (>= 2.0.1)
- Inkslab.Transactions (>= 2.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 3.1.0)
- Microsoft.Extensions.Logging.Abstractions (>= 3.1.0)
- Microsoft.Extensions.ObjectPool (>= 6.0.36)
- System.ComponentModel.Annotations (>= 4.6.0)
-
net10.0
- Inkslab (>= 2.0.1)
- Inkslab.Transactions (>= 2.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 3.1.0)
- Microsoft.Extensions.Logging.Abstractions (>= 3.1.0)
- Microsoft.Extensions.ObjectPool (>= 6.0.36)
-
net6.0
- Inkslab (>= 2.0.1)
- Inkslab.Transactions (>= 2.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 3.1.0)
- Microsoft.Extensions.Logging.Abstractions (>= 3.1.0)
- Microsoft.Extensions.ObjectPool (>= 6.0.36)
-
net8.0
- Inkslab (>= 2.0.1)
- Inkslab.Transactions (>= 2.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 3.1.0)
- Microsoft.Extensions.Logging.Abstractions (>= 3.1.0)
- Microsoft.Extensions.ObjectPool (>= 6.0.36)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Inkslab.Linq:
| Package | Downloads |
|---|---|
|
Inkslab.Linq.MySql
Package Description |
|
|
Inkslab.Linq.SqlServer
Package Description |
|
|
Inkslab.Linq.PostgreSQL
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 2.0.0 | 238 | 10/27/2026 | |
| 1.2.83 | 368 | 6/30/2026 | |
| 1.2.82 | 263 | 6/29/2026 | |
| 1.2.81 | 270 | 6/10/2026 | |
| 1.2.80 | 251 | 6/9/2026 | |
| 1.2.78 | 260 | 5/29/2026 | |
| 1.2.77 | 249 | 4/27/2026 | |
| 1.2.76 | 246 | 4/22/2026 | |
| 1.2.75 | 245 | 4/21/2026 | |
| 1.2.74 | 247 | 4/9/2026 | |
| 1.2.73 | 244 | 4/9/2026 | |
| 1.2.72 | 251 | 4/8/2026 | |
| 1.2.70 | 259 | 4/7/2026 | |
| 1.2.69 | 246 | 4/3/2026 | |
| 1.2.68 | 255 | 3/31/2026 | |
| 1.2.67 | 248 | 3/27/2026 | |
| 1.2.66 | 260 | 3/24/2026 | |
| 1.2.65 | 288 | 3/16/2026 | |
| 1.2.64 | 271 | 3/13/2026 | |
| 1.2.61 | 261 | 2/24/2026 |