The Real Cost of Returning the Identity Value in EF Core
When you insert thousands of rows into SQL Server with Entity Framework Core, performance drops quickly. Most developers blame change tracking. But there is another hidden cost that slows down every SaveChanges call: returning database-generated identity values back to your entities. If your table has an auto-increment primary key (like most SQL Server tables), EF Core must ask the database for…
Many developers blame change tracking when they notice performance issues when inserting thousands of rows using Entity Framework Core. However, there is another hidden cost that can significantly slow down every SaveChanges call, and it is returning database-generated identity values back to your entities. In SQL Server, if you have an auto-increment primary key, EF Core needs to make a round-trip to the database to retrieve each generated identity after the insert.
This extra SQL logic and round-trip limit the batch size, forcing additional overhead, and is the primary reason SaveChanges struggles when handling large batches of data.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.