[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: 


If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.


© 2023 - ErnesTech LLC- Privacy