Can not insert entity with the same key if key is not databa
Posted: Fri 30 Mar 2012 18:05
I am trying to insert a new records in comp_style table. Instead of updating records I delete them all first and then re-create them using the same PK as they had before, in order to keep the same id’s.
I get the Exception "Can not insert entity with the same key if key is not database generated". I am using dotConnect for Oracle version 6.70.
If records were not deleted first I would expect to get this error, since it would be a duplicate key.
But I delete records first, so the record I am about to create is brand new record, and PK IS NOT REPEATING since it is already deleted.
below is my code (simplified):
thank you
I get the Exception "Can not insert entity with the same key if key is not database generated". I am using dotConnect for Oracle version 6.70.
If records were not deleted first I would expect to get this error, since it would be a duplicate key.
But I delete records first, so the record I am about to create is brand new record, and PK IS NOT REPEATING since it is already deleted.
below is my code (simplified):
Code: Select all
using (DbTransaction transaction = DB.Connection.BeginTransaction()) {
// first I delete set of rows from comp_Style table
context.ExecuteCommand("DELETE FROM comp_Style WHERE job_num = 1");
......
// later on in a code I recreate the rows I deleted
CompStyle styleDB = new CompStyle();
styleDB.CounterId = counterID;
// CounterId is Primary Key, I am reusing the same ID(counterID) from the record I deleted previously
context.CompStyles.InsertOnSubmit(styleDB);
// this is when I get the exception
}