.NET Conf is Microsoft’s annual online developer conference for the .NET ecosystem. The 2025 edition highlighted Guid.CreateVersion7() — introduced in .NET 9 — as the idiomatic way to generate time-ordered GUIDs in C# without any third-party dependency. Sessions covered Entity Framework Core integration patterns, the SQL Server UNIQUEIDENTIFIER byte-ordering limitation that affects UUID v7 sort performance, and migration strategies from Guid.NewGuid() (UUID v4) to Guid.CreateVersion7(). This page summarises the key technical points for .NET developers.

Guid.CreateVersion7 in .NET 9

using System;

// .NET 9+ — no NuGet package required
var id = Guid.CreateVersion7();
Console.WriteLine(id);
// "019236a7-b4f2-7000-8d3e-9c1a2b3d4e5f"

// With explicit timestamp (for testing / replay)
var timestamp = DateTimeOffset.UtcNow;
var deterministicId = Guid.CreateVersion7(timestamp);

// Verify version
Console.WriteLine(id.Version); // 7 (available in .NET 9)

Prior to .NET 9, UUID v7 required packages like UUIDNext on NuGet or Uuid.Net. The built-in implementation follows RFC 9562 and is documented at learn.microsoft.com/dotnet/api/system.guid.createversion7.

Entity Framework Core value generator

// GuidVersion7ValueGenerator.cs
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.ValueGeneration;

public class GuidVersion7ValueGenerator : ValueGenerator<Guid>
{
    public override Guid Next(EntityEntry entry)
        => Guid.CreateVersion7(DateTimeOffset.UtcNow);

    public override bool GeneratesTemporaryValues => false;
}

// DbContext configuration
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<Order>()
        .Property(o => o.Id)
        .HasValueGenerator<GuidVersion7ValueGenerator>();
}

The EF Core generated values documentation covers value generator registration and the GeneratesTemporaryValues flag — set false because UUID v7 values are final (not temporary client-side stubs).

SQL Server UNIQUEIDENTIFIER byte-order issue

SQL Server stores UNIQUEIDENTIFIER in a mixed-endian format:

GroupsStorage order
First 4 bytes (group 1)Little-endian
Next 2 bytes (group 2)Little-endian
Next 2 bytes (group 3)Little-endian
Last 8 bytes (groups 4–5)Big-endian

This means UUID v7 values do not sort correctly as UNIQUEIDENTIFIER — the timestamp bits in group 1 are byte-swapped in storage, destroying the lexicographic ordering that makes UUID v7 index-friendly. Two solutions presented at .NET Conf:

Option 1: Store as BINARY(16) with manual byte swap

public static byte[] GuidToSortableSqlBytes(Guid guid)
{
    var bytes = guid.ToByteArray();
    // Swap groups 1, 2, 3 from little-endian to big-endian
    Array.Reverse(bytes, 0, 4);
    Array.Reverse(bytes, 4, 2);
    Array.Reverse(bytes, 6, 2);
    return bytes;
}

Option 2: Use NEWSEQUENTIALID() for SQL Server and accept v4 semantics

-- SQL Server native sequential GUID (not UUID v7, but index-friendly)
CREATE TABLE Orders (
    Id UNIQUEIDENTIFIER PRIMARY KEY DEFAULT NEWSEQUENTIALID(),
    ...
);

NEWSEQUENTIALID() generates sequential GUIDs that sort correctly as UNIQUEIDENTIFIER but are not portable across databases. The NEWSEQUENTIALID documentation covers the limitations — values only increase on the same machine and reset on reboot.

For PostgreSQL via Npgsql, UUID v7 sorts correctly — use Guid.CreateVersion7() and the PostgreSQL uuid column type without any byte swapping.

Minimal API with UUID v7

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapPost("/orders", (CreateOrderRequest req) =>
{
    var order = new Order
    {
        Id = Guid.CreateVersion7(),
        CustomerId = req.CustomerId,
        Total = req.Total,
        CreatedAt = DateTimeOffset.UtcNow
    };
    // db.Orders.Add(order); db.SaveChanges();
    return Results.Created($"/orders/{order.Id}", order);
});

record CreateOrderRequest(Guid CustomerId, decimal Total);
record Order(Guid Id, Guid CustomerId, decimal Total, DateTimeOffset CreatedAt);

The ASP.NET Core Minimal API documentation covers route handlers, parameter binding, and Results helper methods.

Extracting the timestamp from Guid.CreateVersion7

// .NET 9+
var id = Guid.CreateVersion7();
var bytes = id.ToByteArray();

// UUID v7 timestamp: first 6 bytes in big-endian (after byte-swap correction)
// Note: ToByteArray() returns mixed-endian — account for storage order
var msBytes = new byte[8];
msBytes[2] = bytes[3]; msBytes[3] = bytes[2]; msBytes[4] = bytes[1]; msBytes[5] = bytes[0]; // group 1 reversed
msBytes[6] = bytes[5]; msBytes[7] = bytes[4]; // group 2 reversed
var unixMs = BitConverter.ToInt64(msBytes.Reverse().ToArray(), 0) >> 16;
var created = DateTimeOffset.FromUnixTimeMilliseconds(unixMs);

Alternatively, pass the original DateTimeOffset alongside the GUID and store it separately — simpler than extracting it from the byte layout.

Further reading

External references

Frequently asked questions

What is Guid.CreateVersion7 in .NET 9?

Guid.CreateVersion7() was introduced in .NET 9 as a built-in method for generating RFC 9562-compliant UUID v7 values. It accepts an optional DateTimeOffset timestamp parameter — Guid.CreateVersion7(DateTimeOffset.UtcNow). Prior to .NET 9, generating UUID v7 required a third-party NuGet package. The Microsoft documentation for Guid.CreateVersion7 covers the method signature and timestamp parameter.

Does UUID v7 sort correctly as SQL Server UNIQUEIDENTIFIER?

No — SQL Server stores UNIQUEIDENTIFIER (GUID) with a non-standard byte order that affects sort results. The first three groups are stored in little-endian order, causing UUID v7 values to sort incorrectly as UNIQUEIDENTIFIER. Use NEWSEQUENTIALID() for server-side sequential GUIDs, or store UUID v7 as BINARY(16) with explicit byte-swapping to preserve sort order. The SQL Server UNIQUEIDENTIFIER documentation and NEWSEQUENTIALID() documentation explain the storage format.

How do I configure Entity Framework Core to use Guid.CreateVersion7?

In EF Core 9+, configure a value generator on the entity primary key: modelBuilder.Entity<Order>().Property(o => o.Id).HasValueGenerator<GuidVersion7ValueGenerator>() where GuidVersion7ValueGenerator overrides Next() to return Guid.CreateVersion7(DateTimeOffset.UtcNow). For PostgreSQL (via Npgsql), set a database default of gen_random_uuid() or uuidv7() (PostgreSQL 18) instead. The EF Core generated values documentation covers value generators and database defaults.