When I create a new entity in the EF using a model generated from a database that I already created in SQL Server, obviously I have an option to set the entity’s ID(Primary Key) within my code whilst declaring the new entity.
For example when I create a new instance of my ‘Value’ table in my code like this:
Value newValue = Value.CreateValue(int valID);
I pass in a number say 12 to valID:
Value newValue = Value.CreateValue(12);
but when I check the Value table’s data in SQL Server the primary key value valID for the new entity is assigned to something other than 12, for example 7. Why is this happening?
Thanks in advance.
Check if your primary key in the database is set up as AUTONUMBER (In Enterprise Manager go to Design mode for a table and check column properties). It means that the database will disregard whatever value you are passing and generate primary key itself.