No primary key specified in table / view

I am trying to use data binding with WPF and Entity Framework.

After adding the data source to my project, I saved my project to check if everything is okay before what I did.

but I have 11 warning / informational messages with the message:

No primary key specified in table / view "MyDataBase.TableName". The key was inferred, and the definition was created as a table / read-only view.

I have 14 tables in which 4 tables have their primary keys and other tables relate to each other using foreign keys

What is the problem? Request for help

+6
source share
4 answers

Each entity in an EF must be uniquely identifiable. EF uses primary database keys to determine entity keys. Although you can work with primary keys to some extent, this is not completely recommended, because it leads to many problems. The main problem is mentioned directly in the error - if the table does not have a primary key, EF marks it as read only because it is not sure that it can uniquely identify the record that needs to be updated.

+4
source

In fact, this is just a warning, but you can never use the save functions, which in my case make EF useless for me for a poorly designed database. I am stuck at work.

+2
source

Define primary keys in your tables and update the entity data model. This can be done after you open your EF model and right-click and select update. Select the update option from the window and confirm your model.

enter image description here

+2
source

you need to delete the EDMX file from your project. now go to your database and add primary keys to each table. After that add the new EDMX to your project. it will work fine. and do not forget to remove the connectionString tag from the configuration file in the project.

0
source

All Articles