Skip to content

UtilityExtensions.CreateGuid.K4QK8HZXCL8NC8QL1WC6Q8BJ2

Mike King edited this page Nov 9, 2025 · 2 revisions

UtilityExtensions.CreateGuid(this DatabaseFacade) Method

Create a Guid that is suitable for use as a database key value.

public static System.Guid CreateGuid(this Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade database);

Parameters

database Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade

The Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade for the context.

Returns

System.Guid
A System.Guid.

Remarks

SQL Server can store GUIDs but because of how they are handled date stamped GUIDs are not sorted in the correct order. This method uses a third party library (UUIDNext) to create GUIDS that are compatible with the supported database types. (The inbuilt EF Core Microsoft.EntityFrameworkCore.ValueGeneration.SequentialGuidValueGenerator> class creates GUIDS for SQL Server that look correct but with have an incorrect version number).

Clone this wiki locally