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

Unable to track an entity of type Questions published

Was this page helpful?

Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful.. Leave ErnesTech Feedback.Feedback



© 2020 - ErnesTech - Privacy