Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 842
demo_user Avatar asked Jan 08 '13 14:01

demo_user


2 Answers

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.

like image 141
Ladislav Mrnka Avatar answered Nov 03 '22 09:11

Ladislav Mrnka


Indeed it is just a warning but you will never be able to use Save functions which in my case makes EF worthless to me for the poorly designed DB I'm stuck working on.

like image 27
JWP Avatar answered Nov 03 '22 09:11

JWP