When re-adding tables to entity-model, they don't appear (edmx)

edmx entity-framework entity-model

Question

Five tables make up my database. I first included those tables, but then removed them because of a relationship compilation problem.

Currently, I'm opening the edmx file and selecting "update model from database" when I want to add them back. Only under the "refresh" tab do I see those tables; not under the add tab.

How can I re-add them?

1
17
7/15/2016 2:26:32 PM

Accepted Answer

You will first need to remove the table from your model before you can add it again. In the [model.Store] tree, you can see a list of tables (see 'Type of browser' window; you may access it from the right-mouse click menu). The table will show up in the 'Add' tab in the 'Update Wizard's' first step when you execute 'Update model from database...'

Actions to take:

  1. Close Visual Studio and your model.
  2. Launch a text editor and select your.edmx file.
  3. The xml entity elements may be found and removed (see the remarks below).
  4. Open Visual Studio and your model.
  5. To update a model from a database, click.

To remove every mention of a table in your Model:

  • Remove any 'EntitySet' child elements with the 'Name' attribute set to [TableNameToReAdd] from the 'EntityContainer' element.
  • Remove any 'AssociationSet' child elements with the 'EntitySet' attribute set to [TableNameToReAdd] from the 'EntityContainer' element whenever a 'End' element is present.
  • Remove any 'EntityType' child elements whose 'Name' attribute is set to [TableNameToReAdd] from the 'EntityContainer' element.
  • Remove any 'Association' child elements with the 'Role' attribute set to [TableNameToReAdd] from the 'EntityContainer' element when a 'End' element is present.
27
7/12/2016 12:50:51 AM

Popular Answer

After reading this and other search options, I have finally discovered a different solution that would enable me to resolve my problem.

From the error message looks like one of your table/view doesn't have a primary key. EF needs every table to have a primary key in order to generate Entity keys. You may still be able to run your application, but I strongly suggest you add primary keys as warned.

link that helped me with my problem.

Updated

If everything is done correctly and the changes are still not visible, try adding a new column or changing the data type.

The best course of action in this situation is to attempt an update manually. If that fails, as advised by @mathijsuitmegen, remove the table and add it again.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow