dotnet / dotnet/efcore

Utilizing the new `CreateVersion7` API for `ValueGeneratedOnAdd`

Open
#34,158 0 comments 40 reactions 0 assignees View on GitHub
area-change-tracking customer-reported needs-design
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

With the new introduction of `Guid.CreateVersion7(DateTimeOffSet.UtcNow);` in .NET 9 (see: https://github.com/dotnet/runtime/issues/103658), there is a native way to have sortable GUID PK's without any additional 3rd party tools or custom value generators.

This new behavior might be excellent to expose in calls to `ValueGeneratedOnAdd` / `ValueGeneratedOnAddOrUpdate`.

## Alternative
The user could implement something like this (simplified):
```csharp
public class UUIDv7Generator : ValueGenerator
{
protected override object NextValue(EntityEntry entry) => Guid.CreateVersion7(DateTimeOffset.UtcNow);

public override bool GeneratesTemporaryValues { get; }
}

public void Configure(EntityTypeBuilder builder)
{
builder.Property(t => t.Id).HasValueGenerator().ValueGeneratedOnAdd();
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.