ADO.NET Entity Framework and identity columns
I know this post is quite old, but this may help the next person arriving hear via a Google search for "Entitiy Framework" and "Identity".
It seems that Entity Frameworks does respect server-generated primary keys, as the case would be if the "Identity" property is set. However, the application side model still requires a primary key to be supplied in the CreateYourEntityHere
method. The key specified here is discarded upon the SaveChanges()
call to the context.
The page here gives the detailed information regarding this.
If you are using Entity Framework 5, you can use the following attribute.
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
You should set the identity columns' identity specification so that the (Is Identity) property is set to true. You can do this in your table designer in SSMS. Then you may need to update the entity data model.
Perhaps that what you mean by saying the "Primary key is an identity column," or perhaps you missed this step.