SqlException: Cannot insert the value NULL into column 'Id', table 'dbo.TableName'; column does not allow nulls. INSERT fails. The statement has been terminated


Question: Why is Entity #Framework throwing an error that "#SqlException: Cannot insert the value NULL into column 'Id', table 'dbo.TableName'; column does not allow nulls. #INSERT fails. The statement has been terminated"?


Login to See the Rest of the Answer

Answer: Make sure that the Id Column Identity Specification in SQL #Server Management has value (Is Identity) set to "Yes". This lets the SQL Server #Database #Engine know to auto increment the Identity #Column which in this case is the "Id" column.



Another thing to check is the declaration or specification of the Entity Model, make sure you are specifying that the column called Id is the Key by annotating in the Model/Entity Class with a declarative of [Key] on top of the property.






Entity Framework
published
v.0.01





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