“IDENTITY_INSERT is set to OFF “ issue

less than 1 minute read

Today I have received an error “"Cannot insert explicit value for identity column in table 'EventLog' when IDENTITY_INSERT is set to OFF."” in the LINQ to SQL data context trying to create a new record in the EventLog table.




It is quite clear that the issue occurs because LINQ is trying to fill in the Id column in the insert statement. I googled just to find out that the easiest way is to remove my table from the model designer and insert again. But for sure there must be another way. And it is in using the “Auto Generated Value” property of this column. Setting it to True resolved the issue: