EF Code First giving me error Cannot insert explicit value for identity column in table ‘People’ when IDENTITY_INSERT is set to OFF. [duplicate]

I get the following error:
Cannot insert explicit value for identity column in table ‘People’ when IDENTITY_INSERT is set to OFF.

I think that the IDENTITY_INSERT is the Auto Increment functionality which is off.
So, check the field PersonId in the database to see if it is an identity.

Besides, maybe this will fix your problem too.

[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int PersonId { get; set; }

Leave a Comment