C# – Entity Data Model Wizard Not Showing New Tables

centity-frameworksql servervisual studio 2012

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.

Best 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.