My database has a Vehicle table with a primary key. I create a new Vehicle object using
new Vehicle();
and update vehicle properties accordingly.
When i try to do
genesisContext.Vehicles.AddObject(vehicle);
The first time the table is successfully updated and the primary key is 0. In all subsequent cases, I get an error when the key is not unique
Violation of PRIMARY KEY 'VEHICLES_PK' constraint. Cannot insert duplicate key in object 'dbo.Vehicles'. \ R \ nThe application was terminated.
(presumably because the primary key set by EF is still 0)
I was aware that EF intelligently designed primary keys, so why is this happening?
sql-server entity-framework
Calanus
source share