H2Sharp.Linq2Db
6.5.3-alpha.4
dotnet add package H2Sharp.Linq2Db --version 6.5.3-alpha.4
NuGet\Install-Package H2Sharp.Linq2Db -Version 6.5.3-alpha.4
<PackageReference Include="H2Sharp.Linq2Db" Version="6.5.3-alpha.4" />
<PackageVersion Include="H2Sharp.Linq2Db" Version="6.5.3-alpha.4" />
<PackageReference Include="H2Sharp.Linq2Db" />
paket add H2Sharp.Linq2Db --version 6.5.3-alpha.4
#r "nuget: H2Sharp.Linq2Db, 6.5.3-alpha.4"
#:package H2Sharp.Linq2Db@6.5.3-alpha.4
#addin nuget:?package=H2Sharp.Linq2Db&version=6.5.3-alpha.4&prerelease
#tool nuget:?package=H2Sharp.Linq2Db&version=6.5.3-alpha.4&prerelease
H2Sharp.Linq2Db
The linq2db provider for H2Sharp — the C# port of H2 Database 2.5.
It is a native H2 provider, not a PostgreSQL provider with renamed types: the SQL, the type names, the functions and the identifier rules are H2 2.5's. The provider is built for .NET 8 and .NET 10, against linq2db 6.5.
Status: alpha, suites green. The provider suite passes 104 tests and the model suite passes 180 on
net8.0andnet10.0; there are no failures, skips orBlockedByPorttests. The provider suite covers all three bulk-copy modes,MERGE-basedInsertOrUpdate, the catalogue, arrays, JSON, XML as text, SQLROW,UNNEST/LATERAL, and registered .NET scalar, table and aggregate functions.
Install
dotnet add package H2Sharp.Linq2Db --prerelease
The package depends on the published H2Sharp engine and on linq2db 6.5.0. The engine package
is itself a prerelease of the H2 2.5 port; the provider follows the engine's versioning rules.
Quick start
using H2Sharp.Data;
using LinqToDB;
using LinqToDB.DataProvider.H2Sharp;
using var source = new H2DataSourceBuilder("Data Source=quickstart;Storage=Memory").Build();
await using var db = H2SharpTools.CreateDataConnection(source);
await db.ExecuteAsync("""
CREATE TABLE "Blogs" (
"Id" integer NOT NULL,
"Name" varchar(100) NOT NULL,
"Created" timestamp NOT NULL,
CONSTRAINT "PK_Blogs" PRIMARY KEY ("Id")
)
""");
await db.InsertAsync(new Blog { Id = 1, Name = "Foo", Created = DateTime.UtcNow });
var blogs = await db.GetTable<Blog>()
.Where(b => b.Name.StartsWith("F"))
.OrderBy(b => b.Id)
.ToListAsync();
[Table("Blogs")]
public class Blog
{
[Column("Id", IsPrimaryKey = true)]
public int Id { get; set; }
[Column("Name")]
public string Name { get; set; } = "";
[Column("Created")]
public DateTime Created { get; set; }
}
The H2DataSource owns the database. It creates the connection (or every connection a data
context needs), keeps an in-memory database alive for its lifetime, and applies its extension
registrations to each connection. A caller that has only a connection string can pass it to
CreateDataConnection; the provider resolves it through H2SharpDataSources, which keeps one
data source per database.
The connection string is the classic ADO.NET key=value spelling. Data Source names the
database, Storage selects Memory or File, and Mode and the other keys are the engine's
settings. A JDBC URL is not a connection string.
// A file database survives the process; one data source owns one file.
await using var file = H2SharpTools.CreateDataConnection("Data Source=./data/app;Storage=File");
// A DataContext takes its connections from the same data source as the string.
using var ctx = new BlogContext("Data Source=quickstart;Storage=Memory");
What works
| Area | What the provider covers |
|---|---|
| Queries | SELECT, WHERE, ORDER BY, GROUP BY, HAVING, DISTINCT, LIMIT/OFFSET |
| Joins | comma, INNER, LEFT, RIGHT, CROSS, ON, USING |
| Subqueries | EXISTS, IN, IN (SELECT …), derived tables, CTEs |
| Set operations | UNION, UNION ALL, INTERSECT, EXCEPT |
| Window functions | ROW_NUMBER, ranks, LAG/LEAD, FIRST_VALUE, NTH_VALUE, NTILE, FILTER |
| DML | INSERT, UPDATE, DELETE, identity keys through FINAL TABLE, sequences |
| Upsert | InsertOrUpdate as H2 MERGE INTO … USING … ON … WHEN MATCHED/NOT MATCHED |
| Bulk copy | RowByRow, MultipleRows and the provider-specific fallback |
| Types | varchar, char, numeric, varbinary, uuid, json, clob, blob, timestamp, time, boolean, integers, reals, date, time, timestamp with time zone, interval |
| Arrays | integer ARRAY, array literals, ARRAY_CONTAINS, ARRAY_CAT, ARRAY_LENGTH, CARDINALITY, = |
| JSON | H2 JSON columns; canonical documents are read back |
| XML | H2 XML construction functions and text-backed XDocument/XmlDocument |
| Row values | SQL ROW values |
| Table functions | SYSTEM_RANGE, UNNEST, and registered .NET table functions |
| Catalogue | tables, columns, types, identity, comments, primary and foreign keys |
| Extensions | registered .NET scalar functions, table functions and aggregates |
| Lifetime | one H2DataSource per database; memory databases live for the source's lifetime and file databases have one owner |
The provider declares H2 2.5's capabilities, not the engine's current ones. Where the engine has not caught up, the gap is recorded in DIVERGENCES.md.
H2 functions and types
H2's built-in functions are available through H2SharpSpecificExtensions:
var names = await db.GetTable<Blog>()
.Where(b => H2SharpSpecificExtensions.ILike(b.Name, "f%"))
.Select(b => H2SharpSpecificExtensions.Upper(b.Name))
.ToListAsync();
Arrays and table functions are first-class:
// UNNEST over the array of every outer row (H2Sharp LATERAL, D-057).
var values = await (from row in db.GetTable<RowWithArray>()
from value in db.Unnest(row.Values)
select value.Value)
.ToListAsync();
// SYSTEM_RANGE gives one row per number.
var page = await (from blog in db.GetTable<Blog>()
from number in db.SystemRange(1, 3)
where number.X <= blog.Id
select new { blog.Name, number.X })
.ToListAsync();
XML is text in H2 2.5. The H2 construction functions produce it, and a registered XMLPARSE
function plus linq2db's converters read it into XDocument/XmlDocument:
using H2Sharp.Data;
using var source = new H2DataSourceBuilder("Data Source=xml;Storage=Memory")
.ConfigureExtensions(extensions => extensions.RegisterUdf<string?, string?>(
"XMLPARSE", xml => xml, deterministic: true))
.Build();
using var db = H2SharpTools.CreateDataConnection(source);
var document = db.Execute<XDocument>("SELECT XMLPARSE($p)", new DataParameter("p", "<xml/>"));
var element = db.Execute<string>("SELECT XMLNODE('a', NULL, 'x')"); // <a>x</a>
.NET functions and aggregates
H2 2.5's SQL aliases are Java classes stored in the database; the C# port does not store executable code (D-037). Its extension API registers .NET functions on the connection instead:
using H2Sharp.Data;
using H2Sharp.Data.Extensions;
using H2Sharp.Values;
using var source = new H2DataSourceBuilder("Data Source=functions;Storage=Memory")
.ConfigureExtensions(extensions =>
extensions.RegisterAggregate("CUSTOM_AVG", () => new CustomAverage()))
.Build();
using var db = H2SharpTools.CreateDataConnection(source);
var rows = await db.GetTable<Row>()
.GroupBy(row => row.GroupName)
.Select(group => group.CustomAvg(row => row.Value))
.ToListAsync();
CustomAverage implements IH2Aggregate / AggregateBase; scalar functions use
RegisterUdf, and table-valued functions use RegisterTableUdf. The SQL names are then called
like ordinary built-ins.
Documentation
- docs/USAGE.md — the guide: connections, mapping, functions, table functions, window functions, scaffolding, catalogue, generated SQL, limitations.
- docs/DIVERGENCES.md — what differs from PostgreSQL, what is still missing in the port, and which upstream tests could be restored.
- docs/DIALECT.md — the H2 SQL the provider writes.
- UPSTREAM.md — where the provider comes from.
- AGENTS.md — the rules the port follows.
Building and testing
The repository builds against the engine's sibling checkout and the released linq2db package:
dotnet build src/H2Sharp.Linq2Db/H2Sharp.Linq2Db.csproj -c Release
dotnet test test/H2Sharp.Linq2Db.Tests/H2Sharp.Linq2Db.Tests.csproj -c Release
dotnet test test/H2Sharp.Linq2Db.ModelTests/H2Sharp.Linq2Db.ModelTests.csproj -c Release
H2SharpProject points at a different engine checkout; LinqToDbProject switches linq2db
from the released package to a local source checkout. The model suite measures the provider's
coverage; the current result is 1069 / 1227 lines (87.12 %).
Related projects
- H2Sharp — the C# port of H2 2.5: https://github.com/dimzon/h2sharp
- H2Sharp.EntityFrameworkCore — the EF Core provider: https://github.com/dimzon/h2sharp-efcore
- linq2db — the ORM this provider plugs into: https://github.com/linq2db/linq2db
License
MIT; see LICENSE and NOTICE.md. The engine is dual-licensed under the MPL 2.0 and the EPL 1.0.
| Product | Versions 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. |
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 |
|---|---|---|
| 6.5.3-alpha.4 | 6 | 12/3/2026 |