[Solved] System.InvalidOperationException: 'Unable to track an entity of type 'EntityName' because its primary key property 'Id' is null


Question: System.InvalidOperationException: 'Unable to track an entity of type 'EntityName' because its primary key property 'Id' is null.

Solution: In the Database Context add  entity.Property(e => e.Id).ValueGeneratedOnAdd()
- After adding this to the Entity Property you might have an error that says: Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot insert explicit value for identity column in table 'Table' when IDENTITY_INSERT is set to OFF.

when this error happens: 







For peering opportunity Autonomouse System Number: AS401345 Custom Software Development at ErnesTech Email Address[email protected]