Skip to content

Commit 2322a1a

Browse files
authored
Docs related to version 7 GUID generation (#349)
See npgsql/efcore.pg#3249
1 parent 20201ce commit 2322a1a

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

conceptual/EFCore.PG/modeling/generated-properties.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
9292

9393
## GUID/UUID Generation
9494

95-
By default, for GUID key properties, a random GUID is generated client-side by the EF provider and sent to the database.
95+
By default, for GUID key properties, a GUID is generated client-side by the EF provider and sent to the database. From version 9.0 and onwards, these GUIDs are sequential (version 7), which are more optimized for database indexes (before version 9.0, these GUIDs were random).
9696

97-
To generate GUID's client-side for non-key properties, configure them as follows:
97+
To have the provider generate GUIDs client-side for **non-key** properties, configure them as follows:
9898

9999
```c#
100100
protected override void OnModelCreating(ModelBuilder modelBuilder)
101101
{
102102
modelBuilder
103103
.Entity<Blog>()
104104
.Property(b => b.SomeGuidProperty)
105-
.HasValueGenerator<GuidValueGenerator>();
105+
.HasValueGenerator<NpgsqlSequentialGuidValueGenerator>();
106106
}
107107
```
108108

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# 9.0 Release Notes
2+
3+
Npgsql.EntityFrameworkCore.PostgreSQL version 9.0 is under development; previews are available on [nuget.org](https://www.nuget.org/packages/Npgsql.EntityFrameworkCore.PostgreSQL).
4+
5+
## UUIDv7 GUIDs are generated by default
6+
7+
When your entity types have a `Guid` key, EF Core by default generates key values for new entities client-side - in .NET - before inserting those entity types to the database; this can be better for performance in some situations. Before version 9.0, the provider generated random GUIDs (version 4) by calling the .NET [`Guid.NewGuid()`](https://learn.microsoft.com/en-us/dotnet/api/system.guid.newguid?view=net-8.0#system-guid-newguid) function. Unfortunately, random GUIDs aren't ideal for database indexing and can cause performance issues.
8+
9+
Version 9.0 of the provider now generates the recently standardized version 7 GUIDs, which is a sequential GUID type that's more appropriate for database indexes and improves their performance. This new behavior is by default and will take effect simply by upgrading the provider version.
10+
11+
See [this post](https://www.cybertec-postgresql.com/en/unexpected-downsides-of-uuid-keys-in-postgresql) for more details and performance numbers on random vs. sequential GUIDs.
12+
13+
Thanks to [@ChrisJollyAU](https://github.com/ChrisJollyAU) and [@Timovzl](https://github.com/Timovzl) for contributing this improvement!
14+
15+
## Contributors
16+
17+
A big thank you to all the following people who contributed to the 9.0 release!
18+
19+
### [Milestone 9.0.0](https://github.com/npgsql/efcore.pg/milestone/61?closed=1)
20+
21+
Contributor | Assigned issues
22+
------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------
23+
[@roji](https://github.com/roji) | [34](https://github.com/Npgsql/efcore.pg/issues?q=is%3Aissue+milestone%3A8.0.0+is%3Aclosed+assignee%3Aroji)
24+
[@ChrisJollyAU](https://github.com/ChrisJollyAU) | [1](https://github.com/Npgsql/efcore.pg/issues?q=is%3Aissue+milestone%3A8.0.0+is%3Aclosed+assignee%3AChrisJollyAU)
25+
[@Timovzl](https://github.com/Timovzl) | [1](https://github.com/Npgsql/efcore.pg/issues?q=is%3Aissue+milestone%3A8.0.0+is%3Aclosed+assignee%3ATimovzl)

0 commit comments

Comments
 (0)