Paduraksa.TypedIds.EntityFrameworkCore
0.1.0
dotnet add package Paduraksa.TypedIds.EntityFrameworkCore --version 0.1.0
NuGet\Install-Package Paduraksa.TypedIds.EntityFrameworkCore -Version 0.1.0
<PackageReference Include="Paduraksa.TypedIds.EntityFrameworkCore" Version="0.1.0" />
<PackageVersion Include="Paduraksa.TypedIds.EntityFrameworkCore" Version="0.1.0" />
<PackageReference Include="Paduraksa.TypedIds.EntityFrameworkCore" />
paket add Paduraksa.TypedIds.EntityFrameworkCore --version 0.1.0
#r "nuget: Paduraksa.TypedIds.EntityFrameworkCore, 0.1.0"
#:package Paduraksa.TypedIds.EntityFrameworkCore@0.1.0
#addin nuget:?package=Paduraksa.TypedIds.EntityFrameworkCore&version=0.1.0
#tool nuget:?package=Paduraksa.TypedIds.EntityFrameworkCore&version=0.1.0
Paduraksa.TypedIds.EntityFrameworkCore
Entity Framework Core mapping for Paduraksa.TypedIds. One model convention maps every typed ID in the model, with nothing to list per property or per entity.
- One convention for every ID. UUID-based IDs are stored as a 16-byte big-endian binary column, and ordered Int64 IDs as an integer. A key, a foreign key, a nullable ID and a collection of IDs all map the same way.
- Order is kept. The binary form is big-endian, so a column sorts the way the string form does, and for the time-ordered kinds that is creation order.
ORDER BYand the index agree. - Readable in JSON. Inside a JSON complex type or a primitive collection, an ID is its string form, so a stored document reads like the API output.
- Int64 seeding.
ObserveInt64OrderedKeysAsyncreads the largest key of every table keyed by an ordered Int64 ID and feeds it to the generator at startup, so new IDs stay above the stored ones when the clock is behind. - Explicit configuration wins. A
HasConversionon a property replaces the convention for that property.
Provider-neutral: it needs Microsoft.EntityFrameworkCore.Relational and no particular database. Tested on SQLite and PostgreSQL. Targets .NET 10 (EF Core 10).
Use
using Paduraksa.TypedIds;
using Paduraksa.TypedIds.EntityFrameworkCore;
public sealed class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
{
public DbSet<User> Users => Set<User>();
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) =>
configurationBuilder.AddTypedIdConventions();
}
public sealed class User
{
public UserId Id { get; set; } = UserId.New();
public string Name { get; set; } = "";
}
At startup, once, before anything creates IDs:
await using var context = await factory.CreateDbContextAsync();
await context.ObserveInt64OrderedKeysAsync(Int64OrderedIdGenerator.Shared);
Column storage
UUID-based IDs are a 16-byte big-endian binary column by default: it sorts in RFC 9562 order on every provider, so UUIDv7 IDs stay in creation order. On PostgreSQL, uuid is the natural type and sorts the same way. Opt in:
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) =>
configurationBuilder.AddTypedIdConventions(options => options.GuidColumns = TypedIdGuidColumns.Native);
Native stores a Guid and lets the provider pick the column type. Keep the default elsewhere: SQL Server's uniqueidentifier sorts by its last six bytes first, so UUIDv7 IDs lose creation order and a clustered key fragments; SQLite and MySQL store a Guid as 36 characters of text, which is larger and slower than binary. Ordered Int64 IDs stay long, and IDs inside JSON stay strings, either way. The setting is fixed per DbContext type.
Queries
Compare IDs directly: db.Users.Where(u => u.Id == id). id.Value can't be translated through the converter. An ID inside a JSON document is text and a column ID is binary, a uuid or an integer, so comparing or joining the two matches nothing: resolve references that live in JSON in memory.
A property needs a setter of any accessibility, possibly on a base type. A property without one, such as UserId Other => Id, stays unmapped. Typed IDs inside an owned type mapped with OwnsOne(...).ToJson() are rejected; use ComplexProperty(...).ToJson().
| 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. |
-
net10.0
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.0)
- Paduraksa.TypedIds (>= 0.1.0)
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 |
|---|---|---|
| 0.1.0 | 128 | 11/19/2026 |