We use PostgreSQL and are in the process of migrating from .NET8 to .NET9 and in doing so, changing from the Legacy POCO mapping to the newer .ToJson() Mapping.
In the attached sample, there is no data actually being modified. In all cases, dbContext.ChangeTracker.HasChanges(); returns false.
.NET8, version 8.0.11
Legacy Poco Mapping: 0ms
.ToJson(): 300ms
.NET9, version 9.0.0
Legacy Poco Mapping: 0ms
.ToJson(): 2500ms
In both cases, .ToJson() takes longer; however, the difference between .NET8 and .NET9 is 10x more.
The sample references .NET9; however, can be changed to .NET8 for testing. It also relies on Docker for Testcontainers.PostgreSql
https://drive.google.com/file/d/1A_VoN9XgrogMEeevV7mtLh5c2s-Ds2rt/view?usp=drive_link