The [Key] data annotation marks a property as an entity’s primary key. In the BoardGame API, placing it on BoardGame.Id tells EF Core to create Id as the primary-key column. section 5.3.6
That mapping can also produce an identity column in the generated migration. SQL Server then assigns and increments IDs automatically, so manually inserting imported IDs fails while IDENTITY_INSERT is OFF. section 5.3.6
Resolve the conflict according to whether existing identifiers matter:
- Remove the BoardGame.Id assignment and let the database generate new IDs. section 5.3.6
- Preserve imported IDs by enabling IDENTITY_INSERT before saving and disabling it afterward inside the transaction. section 5.3.6
Board-game data seeding
A PUT /Seed request fails with a 500 response when CSV identifiers are assigned to BoardGame.Id. Preserving those identifiers requires temporarily enabling IDENTITY_INSERT during SaveChangesAsync. section 5.3.6
Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details. ---> Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot insert explicit value for identity column in table 'BoardGames' when IDENTITY_INSERT is set to OFF.
Inspect the database error produced when explicit values are inserted into an identity column with IDENTITY_INSERT disabled. section 5.3.6
