If you set your primary key as identity then you dont need to insert primary key it violate primary key rule, its take automatic value, you dont need to pass value at all.
I try insert a record with identity primary key..and it is complaining primary key violation.
Well,everytime when you try to insert an instance into the db,plz check whether the primary key is included or not with if statement……and then do inserting……
vincephuah
Member
184 Points
111 Posts
entity framework primary key constraint violation
Mar 30, 2012 05:30 PM|LINK
How does locking work in EF?
I try insert a record with identity primary key..and it is complaining primary key violation.
Does EF lock a TABLE?? The issue disappear after 20 minutes.
mikeprince.a...
Member
278 Points
54 Posts
Re: entity framework primary key constraint violation
Mar 30, 2012 05:46 PM|LINK
If you set your primary key as identity then you dont need to insert primary key it violate primary key rule, its take automatic value, you dont need to pass value at all.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: entity framework primary key constraint violation
Apr 01, 2012 12:34 AM|LINK
Well,everytime when you try to insert an instance into the db,plz check whether the primary key is included or not with if statement……and then do inserting……
Reguards!
vincephuah
Member
184 Points
111 Posts
Re: entity framework primary key constraint violation
Apr 01, 2012 02:05 AM|LINK
i try doing it in sql management studio and it still complain same error - primary key violation.
I am not inserting any identity. I think there is some locking issue with EF.
I am using Unit Of Work Design pattern. Thanks.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: entity framework primary key constraint violation
Apr 01, 2012 03:35 AM|LINK
What do you mean?If you do this in SQL Management Studio and it still fails……
vincephuah
Member
184 Points
111 Posts
Re: entity framework primary key constraint violation
Apr 01, 2012 04:14 AM|LINK
I try to insert a record in SQL management studio and it complaint the same error.
The issue goes away after 20 minutes.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: entity framework primary key constraint violation
Apr 01, 2012 09:59 AM|LINK
Have you duplicated a key value in the primary?
vincephuah
Member
184 Points
111 Posts
Re: entity framework primary key constraint violation
Apr 01, 2012 07:15 PM|LINK
No. it is an identity field.
I am guessing EF holding a lock to the entire table? or something wrong with the db set up...
Am i the only person getting this weird issue?
vincephuah
Member
184 Points
111 Posts
Re: entity framework primary key constraint violation
Apr 03, 2012 07:31 PM|LINK
I think the issue is that something went wrong with transaction and it locked the table.