Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jul 24, 2012 06:22 PM by Arne Garvander
Jul 23, 2012 07:18 PM|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 07:20 PM|LINK
In your stored procedure, you have to add the line:
SET IDENTITY_INSERT ON
Jul 23, 2012 07:23 PM|LINK
I can't do that because I am not using a stored proc. I am using the Entity Framework,
Jul 23, 2012 07:25 PM|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 07:32 PM|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 07:39 PM|LINK
you dont need to provide identity column values in entity framework while inserting.
hope this will help you :
Jul 23, 2012 08:04 PM|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 06:22 PM|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.