IDENTITY_INSERT is a SQL Server session setting that controls whether explicit values can be written to an identity column. It is OFF by default, so the database normally generates and increments the column value. section 5.3.6
When seeding BoardGames data, assigning existing IDs while IDENTITY_INSERT is OFF causes a DbUpdateException. Preserve those IDs by enabling the setting immediately before saving, then disabling it afterward. section 5.3.6
Wrap explicit-ID inserts in a transaction
using var transaction = _context.Database.BeginTransaction(); _context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT BoardGames ON"); await _context.SaveChangesAsync(); _context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT BoardGames OFF"); transaction.Commit(); The transaction keeps enabling, inserting, and disabling atomic. ExecuteSqlRaw is required because IDENTITY_INSERT is specific to SQL Server. section 5.3.6
