Last post Jul 24, 2012 07:22 PM by Arne Garvander
Jul 23, 2012 08:18 PM|Arne Garvander|LINK
I have a WPF application that I have converted from adding records with stored procs and change to add records with Entity Framework.
Adding records into Sql 2012 works fine on the development machine with the entity framework. The production has sql 2008 and I am not able to add records using entity framework. I get the error message:
Cannot insert explicit value for identity column in table 'Problem' when IDENTITY_INSERT is set to OFF
What should I look for to solve this problem?
Jul 23, 2012 08:20 PM|adamturner34|LINK
In your stored procedure, you have to add the line:
SET IDENTITY_INSERT ON
Jul 23, 2012 08:23 PM|Arne Garvander|LINK
I can't do that because I am not using a stored proc. I am using the Entity Framework,
Jul 23, 2012 08:25 PM|Rohit Rao|LINK
Check the Auto Generated Value property of the column in you Entity FrameWork designer :
It should be set to false to insert the explicit values.
Hope it helps you,
Jul 23, 2012 08:32 PM|Arne Garvander|LINK
I don't think I understand your answer. For 20 years I have seen identity column automatically getting populated. Maybe the entity framework is trying to insert an explicit value behind the scene, by misstake.
Jul 23, 2012 08:39 PM|Rohit Rao|LINK
you dont need to provide identity column values in entity framework while inserting.
hope this will help you :
Jul 23, 2012 09:04 PM|Arne Garvander|LINK
I am using Visual Studio 2010 professional and Visual Studio 2010 c# Express. My properties does not look the same as yours. What are you using?
Jul 24, 2012 07:22 PM|Arne Garvander|LINK
I found my own problem. A SQL identity was missing from development database. Nowhere in my Entity Framework database designer could I see my problem. I had to go into SQL server where I found my error.