Entity Data Model Wizard Not Showing New Tables

c# entity-framework sql-server visual-studio-2012

Question

I've created a sql database from scripts using Microsoft SQL Server 2012 and generated some classes in C# using the entity framework. Now I've had to modify and add a number of new items to that database, including stored procedures and new tables.

However, on trying to regenerate the classes in Visual Studio Ultimate 2012, the Entity Data Model Wizard is still showing the old database (the way it looked a week ago), including some tables I deleted. None of the new stuff is listed. I've tried deleting and recreating the database, restarting both programs, and restarting the pc to no effect.

The steps I'm taking to generate the framework in Visual Studio are:

  • Add a new item to the project.
  • Select ADO.NET Entity Data Model.
  • Select Code First from database.
  • Select Next (the connection string is already filled in).
  • The next screen is the "Choose Objects and Settings" window, which is where I'm still seeing the old tables (and not the new ones).

Is there some special step I need to take after changing a database to get those changes to show up in the entity framework?

UPDATE:

I've got a lead on an option to "Update Model from Database", but my Visual Studio has no option like this. Web searches indicate it's found in the "Model Browser Window", which I've also not found in VS. Further searches indicate this window becomes available after opening an "edmx" file. I've searched the entire pc for that file extension and found some results, but they are all from other peoples' projects. I can't locate a .edmx associated with either the c# solution or the sql database for this project.

1
6
12/3/2014 7:02:26 PM

Accepted Answer

In the Entity Data Model Wizard, on the "Choose Your Data Connection" screen, I chose "New Connection" rather than hitting "Next" with the existing connection. Choosing the server name and database name and redoing the connection seems to refresh the view, and now the new tables have shown up.

I had a feeling it was going to be some small, ten-second thing I was missing.

UPDATE:

Redoing the connection made the new tables available, but not the stored procedures. Here's how I fixed it.

In the Model Wizard, choosing "Code First From Database" won't include stored procedures, for whatever reason. For me, the correct option was "EF Designer from Database". Not only did I get the new tables AND stored procedures, but it also generated the edmx file that the first option wouldn't create.

2
12/4/2014 10:16:13 PM

Popular Answer

I had a similar problem with Code First. I followed all the steps mentioned on the question, but the model for the table was not being generated.

  • Build, Clean Solution
  • Delete conn strings from in web.config
  • Delete all files in Models folder
  • Right click on Models folder, Add, New Item
  • Select ADO.NET Entity Data Model
  • Add name to Model
  • Select Code First from database
  • Select New Connection
  • Save Connection Settings in web.config - Checked

I found out it was because the table did not have a primary key. So I altered the table

[OrderId] [int] not null identity(1,1) primary key,

and it worked.

In case anyone runs into this, I hope it helps.



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