Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilizing the new CreateVersion7 API for ValueGeneratedOnAdd #34158

Open
linkdotnet opened this issue Jul 4, 2024 · 0 comments
Open

Utilizing the new CreateVersion7 API for ValueGeneratedOnAdd #34158

linkdotnet opened this issue Jul 4, 2024 · 0 comments

Comments

@linkdotnet
Copy link

With the new introduction of Guid.CreateVersion7(DateTimeOffSet.UtcNow); in .NET 9 (see: dotnet/runtime#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):

public class UUIDv7Generator : ValueGenerator
{
    protected override object NextValue(EntityEntry entry) => Guid.CreateVersion7(DateTimeOffset.UtcNow);

    public override bool GeneratesTemporaryValues { get; }
}

public void Configure(EntityTypeBuilder<MyEntity> builder)
{
    builder.Property(t => t.Id).HasValueGenerator<UUIDv7Generator>().ValueGeneratedOnAdd();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants