UUIDNext 4.0.0

dotnet add package UUIDNext --version 4.0.0                
NuGet\Install-Package UUIDNext -Version 4.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UUIDNext" Version="4.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UUIDNext --version 4.0.0                
#r "nuget: UUIDNext, 4.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install UUIDNext as a Cake Addin
#addin nuget:?package=UUIDNext&version=4.0.0

// Install UUIDNext as a Cake Tool
#tool nuget:?package=UUIDNext&version=4.0.0                

UUIDNext

A fast and modern .NET library to generate UUID/GUID that are either sequential and database friendly (versions 7 & 8), name based (versions 5) or random (version 4).

How to Install

UUIDNext is available on nuget.org

How to Use

using System;
using UUIDNext;

// Creating a database friendly UUID for PostgreSQL (version 7) or MS SQL Server (Version 8)
Guid sequentialUuid = Uuid.NewDatabaseFriendly(Database.PostgreSQL);
Console.WriteLine($"This is a PostgreSQL friendly UUID : {sequentialUuid}");

Guid sequentialUuid = Uuid.NewDatabaseFriendly(Database.SqlServer);
Console.WriteLine($"This is a SQL Server friendly UUID : {sequentialUuid}");



// Creating a name based UUID (Version 5)
Guid urlNamespaceId = Guid.Parse("6ba7b811-9dad-11d1-80b4-00c04fd430c8");
Guid nameBasedUuid = Uuid.NewNameBased(urlNamespaceId, "https://github.com/uuid6/uuid6-ietf-draft");
Console.WriteLine($"This is a name based UUID : {nameBasedUuid}");

What are all these versions ? I didn't know there were so many types of GUID

The traditional GUID (a.k.a UUID Version 4) is fine and works really well for it's intended use. But its random nature is problematic in some scenarios that's why other UUID versions have been created.

UUID Version 3 and 5 are name-based UUIDs. They take a namespace and a name as input and produce a hash-like UUID. Usage of Version 3 is discouraged as it is based on the obsolete MD5 hash function.

UUID Version 7 and 8 are intended to be used as a primary key in a database. The randomness of UUID V4 has a negative impact on performance when used as a key in a database and UUID V1 exposed the MAC address of the machine where it was created. UUID V7 & 8 aims to take the best of both worlds without their drawbacks.

Why creating a new Library ? is there a problem with Guid.NewGuid() ?

As I said, UUIDs V4 produced by Guid.NewGuid() are fine when they are not used in the scenarios described above and there's no reason to stop using them. But if you find yourself in a position where UUID V4 is suboptimal, this library is for you.

Now that .NET 9 can generate UUID v7, do I still need this library ?

The fact that the .NET team added UUID v7 support is a good news but their implementation is pretty simple : it's just a timestamp in ms completed by random data. This may be fine in some use cases but can cause issue in others. To sum up, you should use UUIDNext if you're in one of these situations:

  • You target a .NET version older than .NET 9 (obviously).
  • You use MS SQL Server. UUIDNext is the only library that generate UUIDs taylored for SQL Server.
  • You do a lot of batch inserts. Contrary to .NET 9, UUIDNext ensure that each generated UUID is greater than the previous one even if they're generated in the same ms.

But wait, there's more !

If you have some special needs, the UuidToolkit class offers a variety of helper methods To create custom UUIDs. If you want to retrieve some information from a UUID like its version or the date when it as created, check the UuidDecoder class.

Resources

Documentation.

RFC 9562 : The new standard for UUID Version 1 to 8.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

  • .NETStandard 2.1

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (9)

Showing the top 5 NuGet packages that depend on UUIDNext:

Package Downloads
Beckett

Messaging and event sourcing library

FastIDs.TypeId

High-performance dotnet implementation of type-safe, K-sortable, globally unique identifier inspired by Stripe IDs

TcKs.TypeId

The .NET implementation of TypeID.

Yaver.Db.Core

Package Description

JamesBrighton.Data.GrpcClient

GrpcDataProvider is a .NET Data Provider for gRPC. This package contains JamesBrighton.Data.GrpcClient.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on UUIDNext:

Repository Stars
mareek/UUIDNext
A fast and modern .NET library to generate UUID/GUID that are either sequential and database friendly (versions 7), name based (versions 5) or random (version 4).
Version Downloads Last updated
4.0.0 8,394 12/4/2024
4.0.0-beta3 314 11/17/2024
4.0.0-beta2 361 10/24/2024
4.0.0-beta 4,580 10/6/2024
3.0.0 394,312 7/2/2024
3.0.0-beta3 5,899 5/16/2024
3.0.0-beta2 25,282 1/24/2024
3.0.0-beta 1,756 11/21/2023
2.0.2 676,986 6/8/2023
2.0.0 107,426 1/9/2023
1.1.1 48,878 4/25/2022
1.1.0 635 4/3/2022
1.0.2 3,796 12/22/2021
1.0.1 1,618 8/27/2021
1.0.0 742 8/23/2021