5

I'm starting a new project using EF 4.1, database first. If I generate the edmx using Visual Studio, then everything is fine; however I can't seem to figure out a way to refresh the edmx when there are changes to the database short of deleting & re-adding it.

In a previous project (using EF 3.x?), we had scripts to do this - edmgen to create the csdl, msl, and ssdl, and then edmgen2 to create the edmx and designer.cs files.

Do I still need to use edmgen2 to create edmx files? Or is there a way with the VS2010 version of edmgen to do this?

chris
  • 36,094
  • 53
  • 157
  • 237

2 Answers2

2

I created a feature request here:
http://data.uservoice.com/forums/72025-entity-framework-feature-suggestions/suggestions/3022790-edmgen-exe-should-support-generating-an-edmx-file-

There are also similar discussions here:
http://social.msdn.microsoft.com/Forums/sa/adodotnetentityframework/thread/a98cddf4-5975-4c20-b88d-d308ed7fa45f

http://social.msdn.microsoft.com/Forums/en/adonetefx/thread/d93cde02-7534-489c-a1bd-72f45ce404be

There is a blog post here:
http://weblogs.asp.net/manavi/archive/2011/05/17/associations-in-ef-4-1-code-first-part-6-many-valued-associations.aspx
(Hint: search for "Get the Runtime EDM")

Those last two links provide the answer:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
  // Additional configuration

  var provider = new DbProviderInfo("System.Data.SqlClient", "2008");
  var model = modelBuilder.Build(provider);
  model.WriteEdmx(provider, new XmlTextWriter(@"C:\temp\my.edmx", Encoding.ASCII));
}
Rami A.
  • 10,302
  • 4
  • 44
  • 87
  • Hi Rami, I am trying to do the same thing. Have you heard back from them or found any solution? – Willem Aug 23 '12 at 06:59
1

Right mouse click in the edmx designer and choose update model from database you will get a popup where you can choose what objects needs updating

Dooie
  • 176
  • 1
  • 6
  • 2
    that does solve my immediate problem, but I would still like to know if there's a way to script the creation of the edmx file. – chris Feb 20 '12 at 14:11