SequentialGuid.EntityFrameworkCore
6.2.0
dotnet add package SequentialGuid.EntityFrameworkCore --version 6.2.0
NuGet\Install-Package SequentialGuid.EntityFrameworkCore -Version 6.2.0
<PackageReference Include="SequentialGuid.EntityFrameworkCore" Version="6.2.0" />
<PackageVersion Include="SequentialGuid.EntityFrameworkCore" Version="6.2.0" />
<PackageReference Include="SequentialGuid.EntityFrameworkCore" />
paket add SequentialGuid.EntityFrameworkCore --version 6.2.0
#r "nuget: SequentialGuid.EntityFrameworkCore, 6.2.0"
#:package SequentialGuid.EntityFrameworkCore@6.2.0
#addin nuget:?package=SequentialGuid.EntityFrameworkCore&version=6.2.0
#tool nuget:?package=SequentialGuid.EntityFrameworkCore&version=6.2.0
SequentialGuid.EntityFrameworkCore
EF Core value-converter support for the SequentialGuid library. Register once and Entity Framework Core can automatically persist SequentialGuid and SequentialSqlGuid properties as standard Guid database columns.
Install
dotnet add package SequentialGuid.EntityFrameworkCore
Supported Frameworks
| Target | EF Core Version |
|---|---|
| .NET 10 | 10.0.0 |
| .NET 9 | 9.0.0 |
| .NET 8 | 8.0.10+ |
Setup
Register the value converters in your DbContext by overriding ConfigureConventions:
using Microsoft.EntityFrameworkCore;
public class AppDbContext : DbContext
{
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
// Registers converters for both SequentialGuid and SequentialSqlGuid
configurationBuilder.AddSequentialGuidValueConverters();
}
}
This single call registers value converters for both SequentialGuid and SequentialSqlGuid so that any entity property of either type is transparently converted to and from Guid when reading/writing to the database.
Entity Model Example
using SequentialGuid;
public class Order
{
// Assigned at construction - no database round-trip needed
public SequentialGuid Id { get; set; } = new();
// Timestamp is always available from the ID itself
public DateTime? CreatedAt => Id.Timestamp;
public string Description { get; set; } = string.Empty;
}
If you are targeting SQL Server and want IDs that sort correctly in uniqueidentifier columns, use SequentialSqlGuid instead:
public class Order
{
public SequentialSqlGuid Id { get; set; } = new();
}
How It Works
Under the hood, SequentialGuidValueConverter<T> (where T : struct, ISequentialGuid<T>) converts:
- To database: extracts the underlying
Guidviavalue.Value - From database: reconstructs the struct via
T.Create(guid), which validates the GUID is a recognized sequential format
This means the database column type remains a standard Guid / uniqueidentifier - no schema changes are needed.
JSON Serialization
If your API returns entities containing SequentialGuid / SequentialSqlGuid properties, register the built-in JSON converters in your Program.cs:
using SequentialGuid.Extensions;
builder.Services.AddControllers()
.AddJsonOptions(o => o.JsonSerializerOptions.AddSequentialGuidConverters());
Value generation
UseSequentialGuidValueGeneration() registers a model-finalizing convention that assigns RFC 9562 v7 sequential value generators to every Guid, SequentialGuid, and SequentialSqlGuid primary-key property. Keys are generated client-side on Add — no database round-trip, retry-safe.
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
configurationBuilder.AddSequentialGuidValueConverters();
configurationBuilder.UseSequentialGuidValueGeneration(); // v7 keys on Add
// configurationBuilder.UseSequentialGuidValueGeneration(sqlServerByteOrder: true);
}
- Plain
Guidkeys get standard byte order; passsqlServerByteOrder: trueto switch to SQL Serveruniqueidentifier-friendly order. SequentialGuid/SequentialSqlGuidkeys carry byte order in the type and ignore the flag.- Explicit
HasValueGenerator<T>()always wins — the convention never overwrites it. - The four generators (
SequentialGuidValueGenerator,SequentialSqlGuidValueGenerator,SequentialGuidStructValueGenerator,SequentialSqlGuidStructValueGenerator) are public for explicit per-property wiring.
Further Reading
See the main SequentialGuid README for full documentation on UUID generation, timestamp extraction, and SQL Server byte-order handling.
| Product | Versions 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. |
-
net10.0
- Microsoft.EntityFrameworkCore (>= 10.0.0)
- SequentialGuid (>= 6.2.0)
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.10)
- SequentialGuid (>= 6.2.0)
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.0.0)
- SequentialGuid (>= 6.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.