Wednesday, December 9, 2009

Error when updating database, IDENTITY_INSERT is set to OFF while coding ASP.NET MVC

If you made changes to the table in the database, after you created your table in the server explorer (*.dbml file)

You need to drop the table from the designer and add it back in to the server explorer.


Open de codebehind file for the database. Something like Project.designer.cs and add it to the Column in question.

[Column(Storage="_FileID", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
The important bit is the IsDbGenerated=true.