Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Model From Database doesn't add new table from database

I have an ADO.NET Entity Data Model created. Everything worked fine, until I added new table in my database. So I wanted to add that table to my data model. I followed these steps: Right click on my model -> Update From Database. Than the wizard opens where I chose what I want to add. When I expand tables tree, my table which I have added to my database is there. I check it and click finish. No errors, everything is successfully done, but there is no any changes on my model. The table is not added to my model. Does anyone know why is this happening?

like image 428
Stojdza Avatar asked Mar 18 '14 10:03

Stojdza


People also ask

How do I add a table to an existing entity model?

Open edmx file, right click anywhere in the modal and select "Update Model from Database" and follow the instructions and choose the desired tables and SPs. Sometimes even after following these steps, your model will not get updated, close Visual Studio and restart it again.

Why update model from database in Entity Framework is not working?

Update model from database in entity framework is not working c#entity-framework Question If any changes have made on the datatype or constraints(e.g. not null - null) of a particular column in table and performing Update model from database(Refresh a particular table) in entity framework is not updating the entity model.

How do I use the update from Database Wizard?

The Update from Database Wizard does the following: If an object has been added to the database (or was not included in the previous model), you can choose to add the object to the model. If an object has been updated, the wizard updates the object definition in the storage model.

Does the update from Database Wizard change the domain model?

The Update from Database Wizard overwrites the domain model when updating the data model based on the database changes. The wizard also makes some changes to the conceptual model and mappings, but it only makes these changes when objects are added or modified in the database.

How are new types and properties added to the model?

For example, new types are added to the model when tables are added to the database, and new properties are added to types when columns are added to a table. If an object has been added to the database (or was not included in the previous model), you can choose to add the object to the model.


2 Answers

When EF complains about certain things (i.e. missing pk) after adding tables to your model trough the "update database" wizard, it does not produce an error or a warning but a message in the error list window. make sure have have checked that. in my case EF was complaining about tables with no primary key defined.

like image 158
chris vietor Avatar answered Sep 21 '22 11:09

chris vietor


Try saving the updated model and then reopening it. I added two tables and although the designer view had a * on it (indicating it was changed), I couldn't see my new tables. On a hunch I closed and reopened the model and the tables were there. This is in VS 2017.

like image 45
Greg Avatar answered Sep 21 '22 11:09

Greg