views:

538

answers:

2

I have no code behind and the above error keep prompting on INSERT. The DBML is refresh!

Exception Details: System.Data.Linq.DuplicateKeyException: Cannot add an entity with a key that is already in use.

A: 

Have a look at this forum

Eric
+3  A: 

Sounds to me like Identity Specification is not enabled on the table's index column. Enable it and update the DBML.

Of course, if your primary key is something that doesn't support Identity Specification, you will need to generate your own primary keys. Entity Framework doesn't use default values you may have set for a column, so if you use a uniqueidentifier column and have set the default value to NEWID(), that might be your problem. In that case, use

myObject.Id = Guid.NewGuid();

from your code.

Thorarin