Entity Framework and Identity column

231 Views Asked by At

Can we INSERT a row into a SQL Server table without any IDENTITY column and primary key?

in Entity Framework 5

1

There are 1 best solutions below

0
On

Entity Framework requires a primary key. Relational databases should have primary keys on all tables. However, you do not need an identity as the primary key. You can use any unique value as the primary key. As long as you populate it, Entity Framework will accept it, although it must be unique, of course.

Using 'smart' (non-identity) keys brings about problems of its own. Any data value is subject to change or correction, so using something like a phone number as a primary key means that you have to propagate changes throughout the database when the data value changes.