ByteAether.Ulid.Dapper
1.3.9-preview.0
Prefix Reserved
dotnet add package ByteAether.Ulid.Dapper --version 1.3.9-preview.0
NuGet\Install-Package ByteAether.Ulid.Dapper -Version 1.3.9-preview.0
<PackageReference Include="ByteAether.Ulid.Dapper" Version="1.3.9-preview.0" />
<PackageVersion Include="ByteAether.Ulid.Dapper" Version="1.3.9-preview.0" />
<PackageReference Include="ByteAether.Ulid.Dapper" />
paket add ByteAether.Ulid.Dapper --version 1.3.9-preview.0
#r "nuget: ByteAether.Ulid.Dapper, 1.3.9-preview.0"
#:package ByteAether.Ulid.Dapper@1.3.9-preview.0
#addin nuget:?package=ByteAether.Ulid.Dapper&version=1.3.9-preview.0&prerelease
#tool nuget:?package=ByteAether.Ulid.Dapper&version=1.3.9-preview.0&prerelease
ULID Dapper Integration
from ByteAether
An official extension package for ByteAether.Ulid, providing seamless integration with Dapper. It enables effortless mapping of Ulid and Ulid? properties to database columns using customizable global persistence strategies.
For the core library and full details, visit our GitHub repository.
Features
- Version Support: Fully compatible with Dapper versions 2.0.0 and newer.
- Automated Configuration: Register mappings globally across your entire application runtime using a single configuration call.
- Flexible Storage Strategies: Choose how your identifiers are mapped based on your database engine constraints:
String: 26-character Crockford's Base32 string (e.g.,CHAR(26)). (Default)Binary: 16-byte binary payload (e.g.,BINARY(16)).Guid: Native UUID format (ideal for PostgreSQLuuid).SqlServerGuid: Shuffled SQL Server sequentialuniqueidentifierto maintain native index sorting properties.
Installation
Install the stable package via NuGet:
dotnet add package ByteAether.Ulid.Dapper
Usage
Call DapperUlid.RegisterUlid() during your application's startup lifecycle (e.g., inside Program.cs or a global initialization block) before executing any queries:
using ByteAether.Ulid.Dapper;
// Configures the mapping globally using your chosen database storage format.
// Supports: UlidStorageFormat.String (Default), Binary, Guid, and SqlServerGuid
DapperUlid.RegisterUlid(UlidStorageFormat.Binary);
Once registered, queries executing via Dapper parameters or multi-mapping configurations handle the translation transparently:
public class User
{
public int Id { get; set; }
public Ulid AccountId { get; set; }
public Ulid? ManagedById { get; set; }
}
// Queries execute seamlessly
var user = connection.QueryFirstOrDefault<User>(
"SELECT * FROM Users WHERE AccountId = @Id",
new { Id = myUlid }
);
⚠️ Important Architectural Limitations & Warnings
1. No Per-Property / Mixed Mappings
Unlike full object-relational mappers (like Entity Framework Core) which preserve structural metadata per table column, Dapper maps .NET types globally via a 1:1 scheme (Type → TypeHandler).
- The Rule: You can choose exactly one global strategy for your application lifecycle.
- The Constraint: If you call
RegisterUlid(UlidStorageFormat.String), you cannot have some tables storingUlidasBINARY(16)and others asVARCHAR(26)within the same execution path. The last configuration registered will override any previous configuration globally. If a mixed scheme is explicitly required, wrapper primitive types or custom parameter objects must be introduced manually.
2. Range Queries & Sorting Compatibility (>=, <=, ORDER BY)
All storage formats are technically supported, but their ability to maintain chronological sorting and support range queries depends entirely on how the underlying database provider handles GUID byte layouts. Because ULIDs rely on a big-endian timestamp for sorting, your choice of database provider determines which formats remain index-friendly:
- Globally Safe (
StringandBinary): These formats preserve the raw left-to-right chronological order of ULIDs natively across all database engines (SQLite, PostgreSQL, SQL Server, etc.). - Provider Dependent (
Guid): Standard.NET Guidstructures use a mixed-endian layout.- PostgreSQL: Supported. The connection driver automatically corrects the endianness when mapping to native
uuidcolumns, preserving chronological sorting. - SQLite / Others: Incompatible for range queries. These engines store GUIDs as raw byte streams, meaning the mixed-endian layout will scramble chronological comparison (though equality operations remain fully functional).
- PostgreSQL: Supported. The connection driver automatically corrects the endianness when mapping to native
- SQL Server Specific (
SqlServerGuid): This format explicitly optimizes byte shuffling for Microsoft SQL Server's unique sequential indexing rules.- Constraint: This format only works as intended if the underlying column is typed as
uniqueidentifier. Storing it asBINARY(16)orVARCHARwill break sorting. - Trade-off: This internal byte reordering sacrifices cross-database compatibility (e.g., migrating data to PostgreSQL or SQLite) in exchange for raw SQL Server index performance.
- Constraint: This format only works as intended if the underlying column is typed as
CRITICAL: Before using
GuidorSqlServerGuidformats for range queries (>=,<=) orOrderByclauses, verify your database provider's native UUID comparison behavior. Misaligning the format with the engine's sorting behavior will result in broken data retrieval and missed records.
Native AOT & Trimming Compatibility
ByteAether.Ulid.Dapper introduces no runtime reflection, dynamic IL injection, or dynamic code compilation patterns inside its mapping block. The explicit SqlMapper.TypeHandler<T> strategy is fully safe for Native AOT compilation and trimming.
Ensure your version of the underlying Dapper framework itself is explicitly configured to support AOT workloads
License
This project is licensed under the MIT License. See the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. 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.0
- ByteAether.Ulid (>= 1.3.9-preview.0)
- Dapper (>= 2.0.4)
-
net10.0
- ByteAether.Ulid (>= 1.3.9-preview.0)
- Dapper (>= 2.0.4)
-
net8.0
- ByteAether.Ulid (>= 1.3.9-preview.0)
- Dapper (>= 2.0.4)
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 |
|---|---|---|
| 1.3.9-preview.0 | 26 | 7/11/2026 |