Search code examples
wpfsql-server-2008entity-framework-4entity-framework-4.1

The table/view does not have a primary key defined


I am trying to use the Databinding with WPF and Entity Framework.

After adding the data-source to my project, I saved my project in order to see whether everything is fine till what I have done.

but I have a 11 warn/info messages stating :

The table/view 'MyDataBase.TableName' does not have a primary key defined. The key has been inferred and the definition was created as a read-only table/view.

I have 14 Tables where 4 tables has their own primary keys and others tables are referred to each other using foreign keys

What is this issue all about? Kindly help


Solution

  • Every entity in EF must be uniquely identifiable. EF uses database primary keys to define entity keys. While it is possible to work without primary keys to some extend it is definitively not recommended because it leads to many issues. The core issue is mentioned directly in the error - if the table doesn't have primary key, EF marks it as read only because it is not sure that it can uniquely identify record to be updated.