I have a table table1, the primary key is Pkey. It is an identity column. I have another table table2 that has no primary key and identity column.
I want to insert the value of Pkey of table1 into id column of table2.
obj2.id = obj1.Pkey;
I get an exception:
Cannot insert the value NULL into column ‘id’, table ‘table2’; column does not allow nulls. INSERT fails.
Thanks for hint. Does the system want to assign the identity property to id?
UPDATE:
Origninally table2 is empty, I created new record from entity framework.
BDetail obj2= iContext.DetailsRecords.Create();
obj2.id = obj1.Pkey;
iContext.BDetail.Add(obj2);
iContext.SaveChanges(); // exception here
Is it possible that obj1 hasn’t been created yet? Hence the NULL value from a primary key (which, if the row exists, can never be NULL).