ADO.NET Entity Framework and identity columns

matthew thomas picture matthew thomas · Sep 23, 2008 · Viewed 44k times · Source

Is the Entity Framework aware of identity columns?

I am using SQL Server 2005 Express Edition and have several tables where the primary key is an identity column. when I use these tables to create an entity model and use the model in conjunction with an entity datasource bond to a formview in order to create a new entity I am asked to enter a value for the identity column. Is there a way to make the framework not ask for values for identity columns?

Answer

biozinc picture biozinc · Dec 23, 2008

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.