Geting "Violation of PRIMARY KEY constraint" error, however there are no
duplicates
I use LINQ to SQL. I have simple one attribute table in SQL, this
attribute is also primary key. I use linq to create corresponding entities
from List<string>. This entity's one and only attribute is token. I
traverse through List<string> (this is deserialized from a xml file), and
create Token entity and set its token attribute to a string from List and
call InsertOnSubmit. After populating Token table, I call SubmitChanges on
context. At this point I get error that I have primary key violation on
some string, let it be "bla bla". I've checked several times inside my xml
file (from which I've deserialized my List<string>) that I have only one
"bla bla". I've tried to remove this "bla bla" from string, after I do
that, I get the same error on other string, and again check the file and
again I have only one of that string inside the file. I even checked
inside the code the count of elements which contain string "bla bla", and
again there count is only 1. I don't know from where LINQ takes another
instance of "bla bla" and I got really angry. Of course I've checked that
I call InsertOnSubmit only one time inside my code for every string. So I
have no idea why I continue to get this primary key violation on "bla
bla". Any Suggestions??
Thanks for the answers
No comments:
Post a Comment