UUID.Serialization.Entity
1.0.1
See the version list below for details.
dotnet add package UUID.Serialization.Entity --version 1.0.1
NuGet\Install-Package UUID.Serialization.Entity -Version 1.0.1
<PackageReference Include="UUID.Serialization.Entity" Version="1.0.1" />
paket add UUID.Serialization.Entity --version 1.0.1
#r "nuget: UUID.Serialization.Entity, 1.0.1"
// Install UUID.Serialization.Entity as a Cake Addin #addin nuget:?package=UUID.Serialization.Entity&version=1.0.1 // Install UUID.Serialization.Entity as a Cake Tool #tool nuget:?package=UUID.Serialization.Entity&version=1.0.1
UUID.Serialization.Entity
Entity Framework Core value converters for UUID types. This package provides converters for storing UUID values in different formats:
- Binary (16 bytes)
- Base64 (24 characters)
- String (32 characters)
Installation
dotnet add package UUID.Serialization.Entity
Usage
Global Configuration
Configure all UUID properties in your DbContext to use a specific storage format:
public class MyDbContext : DbContext
{
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
// Use binary storage (most efficient, 16 bytes)
configurationBuilder.UseUUIDAsBinary();
// Or use string storage (32 characters)
// configurationBuilder.UseUUIDAsString();
// Or use base64 storage (24 characters)
// configurationBuilder.UseUUIDAsBase64();
}
}
Per-Property Configuration
Configure individual properties to use specific storage formats:
public class MyDbContext : DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>()
.Property(e => e.Id)
.UseUUIDAsBinary();
modelBuilder.Entity<AuditLog>()
.Property(e => e.Id)
.UseUUIDAsString();
modelBuilder.Entity<Session>()
.Property(e => e.Id)
.UseUUIDAsBase64();
}
}
Database Schema Examples
-- For binary storage (most efficient, 16 bytes)
CREATE TABLE Users (
Id INTEGER PRIMARY KEY,
UserId BLOB -- SQLite
-- or: UserId BINARY(16) -- SQL Server
-- or: UserId BYTEA -- PostgreSQL
);
-- For string storage (32 characters)
CREATE TABLE AuditLogs (
Id INTEGER PRIMARY KEY,
UserId CHAR(32) -- Fixed-length string
);
-- For base64 storage (24 characters)
CREATE TABLE Sessions (
Id INTEGER PRIMARY KEY,
UserId VARCHAR(24) -- Base64 encoded
);
Features
Multiple Storage Formats
- Binary storage (16 bytes) for maximum efficiency
- Base64 storage (24 characters) for balanced approach
- String storage (32 characters) for human readability
Flexible Configuration
- Global configuration through
ConfigureConventions
- Per-property configuration using fluent API
- Easy to switch between storage formats
- Global configuration through
Database Compatibility
- Works with all major databases (SQL Server, PostgreSQL, SQLite, etc.)
- Automatic type mapping
- Proper size hints for database schema generation
Performance Optimized
- Zero-allocation conversions where possible
- Efficient byte array handling
- Minimal memory footprint
Best Practices
- Use base64 storage (
UseUUIDAsBase64
) for a balance between readability and storage size. - Use binary storage (
UseUUIDAsBinary
) for the most efficient storage and best performance. - Use string storage (
UseUUIDAsString
) when you need human-readable values or easier debugging.
Requirements
- UUID library
- Supports .NET 6.0 or later
- Microsoft.EntityFrameworkCore 6.0.0 or later
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the terms of the LICENSE file included in the root directory.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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 is compatible. 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 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. |
-
net6.0
- Microsoft.EntityFrameworkCore (>= 6.0.36)
- UUID (>= 1.1.1)
-
net7.0
- Microsoft.EntityFrameworkCore (>= 7.0.20)
- UUID (>= 1.1.1)
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.11)
- UUID (>= 1.1.1)
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.0.0)
- UUID (>= 1.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
All changes are detailed at https://github.com/Taiizor/UUID/wiki/Changelog.