简体   繁体   中英

Database First EntityType 'table' has no key defined. Define the key for this EntityType

I Create the model starting from a Oracle Database. In the table that I picked there isn't a primary key so the entity framework complains about that and it is not able to generate the classes correctly. Do you know a way to generate the model in the correct way without adding the primary key to the database?

One way of adding a primary key to a table after you have created your model is to open this file [1]: https://i.stack.imgur.com/6vJhP.png . Once inside you will see all the relevant tables on the model. [1]: https://i.stack.imgur.com/bSIsK.png . Right click on the column you wish to make the primary key, you will see the wording "Entity Key", make sure this is ticked/selected as in the image. Save the model, and rebuild project. This should be done on all tables complaining of primary keys. Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM