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


Edit this Article
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
If you log in, you will be notified when someone leaves a comment.

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

Your Session is Ending
Login to Continue

© 2021 - ErnesTech - Privacy