Muhammad Ashhar Hasan
Muhammad Ashhar Hasan

Reputation: 299

Make Model from Database using ADO.NET Entity Framework

I have a database and I want to make a model from it then later controllers and views. I went to "Models" folder then clicked on "Add New Item" but unable to find Entity Data Model. However Entity Framework 5 is already installed and reference is also present and I am using visual studio 2013 ultimate. I also tried nuget package manager but it is also confirming that Entity Framework is already installed. I think I am missing some thing or doing somthing wrong. Please help me how to generate a model from a database.

Upvotes: 1

Views: 4631

Answers (2)

Muhammad Ashhar Hasan
Muhammad Ashhar Hasan

Reputation: 299

I uninstalled the visual studio and then installed it again. It solved my problem. Some components like visual studio database tools were not installed correctly. And it would also work if I would choose the repair option.

Upvotes: 1

jim tollan
jim tollan

Reputation: 22485

You'll need to creat an edmx file which captures your model from the database. the steps to do this are as follows:

To create an .edmx file from an existing database

  • Open or create the project for which you want to create an .edmx file.
  • Right-click the project name in Solution Explorer, point to Add, and then click New Item.
  • Select ADO.NET Entity Data Model in the Templates pane.
  • Enter the name for the file (.edmx), and then click Add.
  • The first page of the Entity Data Model Wizard appears.
  • Select Generate from database in the Choose Model Contents dialog box, and then click Next.
  • Click the New Connection button.
  • The Connection Properties dialog box appears.
  • Enter the server name, select the authentication method, and enter the name of the database for which the model is being created. Click OK.
  • The Choose Your Data Connections dialog box is updated with the database connection settings.
  • Click Next to continue.
  • The Choose Your Database Objects dialog box appears. By default, no objects in the database are selected for inclusion in the .edmx file.
  • Expand the nodes for Tables, Views, and Stored Procedures. Cancel the selection of any tables, views, and stored procedures that you do not want included in the .edmx file.
  • Click Finish to create the .edmx file.

this can be referenced more fully at: http://msdn.microsoft.com/en-us/library/vstudio/cc716703%28v=vs.100%29.aspx

[edit] - this is how the new item dialog should look:

enter image description here

Then when creating controllers/views, you just point to the required model in the select list, i.e:

enter image description here

Upvotes: 0

Related Questions