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
                    
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="Paduraksa.TypedIds.EntityFrameworkCore" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Paduraksa.TypedIds.EntityFrameworkCore" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Paduraksa.TypedIds.EntityFrameworkCore" />
                    
Project file
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 Paduraksa.TypedIds.EntityFrameworkCore --version 0.1.0
                    
#r "nuget: Paduraksa.TypedIds.EntityFrameworkCore, 0.1.0"
                    
#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 Paduraksa.TypedIds.EntityFrameworkCore@0.1.0
                    
#: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=Paduraksa.TypedIds.EntityFrameworkCore&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Paduraksa.TypedIds.EntityFrameworkCore&version=0.1.0
                    
Install as a Cake Tool

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 BY and 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. ObserveInt64OrderedKeysAsync reads 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 HasConversion on 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 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.

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