Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add table in Entity Framework?

I have a project that I made in Asp.net with Entity Framework.

Now I want to add one or more tables in the database and one or more stored procedures. But entities not shows the new table.

How to show this?

like image 669
chetan singhal Avatar asked Jun 24 '11 10:06

chetan singhal


People also ask

How do I display a table in Entity Framework?

Right-click the Models folder in the Solution Explorer window and the select the menu option Add, New Item. Select the Data category and select the ADO.NET Entity Data Model template. Give your data model the name MoviesDBModel. edmx and click the Add button.

How do I add a table to EDMX Entity Framework?

Open the edmx file. Right Click anywhere but the tables or relationships. Select "Update Model from Database". Then select 'tables' checkbox in the next dialog box that appears after it has retrieved the data from the underlying database.

Does Entity Framework create tables?

If you're using a Code First approach then Entity Framework will build the table for you. It looks like you are not using Code First, so you will have create the table in the database.


2 Answers

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.

enter image description here

Sometimes even after following these steps, your model will not get updated, close Visual Studio and restart it again. This has happened many times for me.

like image 53
Sharique Avatar answered Sep 23 '22 12:09

Sharique


Sharique's answer is the good one. But I noticed a thing: when the Mapping Details window is active(near Error List, Output) and if you are trying to add a new Entity (right click the design surface, Add -> Entity), the popup dialog, "Add Entity" it won't show.

like image 33
Adrian Iftode Avatar answered Sep 22 '22 12:09

Adrian Iftode