-
Notifications
You must be signed in to change notification settings - Fork 0
UtilityExtensions.CreateGuid.K4QK8HZXCL8NC8QL1WC6Q8BJ2
Mike King edited this page Nov 9, 2025
·
2 revisions
Create a Guid that is suitable for use as a database key value.
public static System.Guid CreateGuid(this Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade database);database Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade
The Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade for the context.
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).