OrionKey 0.5.0

dotnet add package OrionKey --version 0.5.0
                    
NuGet\Install-Package OrionKey -Version 0.5.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="OrionKey" Version="0.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OrionKey" Version="0.5.0" />
                    
Directory.Packages.props
<PackageReference Include="OrionKey" />
                    
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 OrionKey --version 0.5.0
                    
#r "nuget: OrionKey, 0.5.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 OrionKey@0.5.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=OrionKey&version=0.5.0
                    
Install as a Cake Addin
#tool nuget:?package=OrionKey&version=0.5.0
                    
Install as a Cake Tool

OrionKey

Source-generated strongly-typed IDs for .NET.

OrionKey turns a readonly partial struct into a fully-featured strongly-typed ID with a single attribute. A bundled Roslyn source generator emits the equality, comparison, factory, serialization, and persistence members, so a domain ID stops being a bare Guid or long and becomes a distinct type the compiler can check. No base class, no runtime reflection, nothing to wire up.

Quick start

dotnet add package OrionKey

Mark a partial struct with [OrionId] and a storage type. The optional second type argument selects a generation strategy:

[OrionId<Guid>]              public readonly partial struct OrderId;
[OrionId<long, Snowflake>]   public readonly partial struct UserId;
[OrionId<string, Ulid>]      public readonly partial struct TenantId;
[OrionId<string, NanoId>]    public readonly partial struct SessionId;

Strategies

Declaration Storage New() Sortable
[OrionId<Guid>] Guid Guid.NewGuid() no
[OrionId<Guid, GuidV7>] Guid UUIDv7 yes
[OrionId<Guid, SequentialGuid>] Guid SQL Server-ordered sequential GUID yes
[OrionId<long, Snowflake>] long Snowflake yes
[OrionId<string, Ulid>] string ULID yes
[OrionId<string, Ksuid>] string KSUID yes
[OrionId<string, ObjectId>] string MongoDB ObjectId (24-char hex) yes
[OrionId<string, NanoId>] string NanoId no
[OrionId<string, Cuid2>] string CUID2 no
[OrionId<int>] / [OrionId<long>] int/long none (DB identity) n/a

The int and long integer forms have no New() factory; they model ids assigned externally, typically by a database identity column.

What gets generated

For every annotated struct the generator emits, as partial companions:

  • The struct body itself: a Value member, a New() factory (strategy-backed types), and value-based IEquatable equality with == / !=.
  • An IComparable / IComparable<T> implementation, emitted only for sortable strategies (GuidV7, SequentialGuid, Snowflake, Ulid, Ksuid, ObjectId).
  • A System.Text.Json JsonConverter so the id serializes as its underlying value.
  • A TypeConverter for framework conversions and ASP.NET Core model binding.
  • IParsable<T> and ISpanParsable<T> implementations for allocation-aware parsing.
  • An EF Core ValueConverter, emitted only when the project references EF Core, so the id can be used directly as an entity key or property.

The generated converters are discovered automatically by System.Text.Json, EF Core, and ASP.NET Core model binding. No manual registration is required.

Library integration

When the consumer project references Dapper, Newtonsoft.Json, MongoDB.Driver, or Swashbuckle.AspNetCore, OrionKey emits matching companions for every [OrionId] struct:

Library Generated companion One-line registration
Dapper <Id>DapperTypeHandler OrionKeyDapperRegistrar.Register();
Newtonsoft.Json <Id>NewtonsoftJsonConverter OrionKeyNewtonsoftJsonRegistrar.AddTo(settings);
MongoDB driver <Id>BsonSerializer OrionKeyMongoRegistrar.Register();
Swashbuckle (OpenAPI) <Id>SchemaFilter OrionKeyOpenApiRegistrar.AddTo(options);

OrionKey is released under the MIT License.

AOT & trimming

OrionKey 0.4+ is compatible with Native AOT and trimming. The runtime assembly carries <IsAotCompatible>true</IsAotCompatible> and a CI matrix publishes a self-contained AOT binary on linux-x64 and win-x64 every push.

Newtonsoft.Json, MongoDB.Driver, Swashbuckle.AspNetCore, and Dapper are not fully AOT-clean as of mid-2026 — prefer System.Text.Json, EF Core, and the BCL TypeConverter/IParsable pipelines in AOT projects. When using System.Text.Json source generation, register the generated <Id>JsonConverter instances into JsonSerializerOptions.Converters and pass the options into new JsonContext(options). For IParsable<T>, invoke T.Parse(text, null) via a where T : IParsable<T> constraint (the emitted Parse is an explicit interface implementation).

Product 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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on OrionKey:

Package Downloads
OrionKey.Testing

Deterministic ID generators for testing code that uses OrionKey strongly-typed IDs.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.0 98 6/2/2026
0.4.1 152 5/25/2026
0.4.0 111 5/24/2026
0.3.1 107 5/23/2026
0.3.0 113 5/23/2026
0.2.0 113 5/23/2026
0.1.0 117 5/21/2026