I'm attempting to create a database record with a predetermined primary key value. I'm aware of how to accomplish this using SQL, but I'm curious whether EF can do it for me. If not, I will need to develop a stored procedure for the inserts.
Should you possess the
Your entity's Entity Key value will be given to the database if attribute is set to "None".
There is no way to control the value that will be assigned to this column in the database if this attribute is set to either "Identity" or "Computed".
Consequently, if your database has an auto-incremented column and the ADO.NET Entity Data Model wizard has specified the
For your benefit, you may use the XML Editor to manually alter this property in the SSDL portion of the model to "None", and then enable
If you're using EF4, you may use the
ObjectContext.ExecuteStoreCommand technique or the
the ability to run a SQL command
SET IDENTITY_INSERT <Your_Table> ON
(in EF v4 and EF v1)