views:

2382

answers:

6
  • So I have my edmx made.
  • Then I change my database a little bit, changing a column to from being a NOT NULL to allowing NULL.
  • I go into my edmx, right click and choose "Update Model from Database"

Now I go into my program and it hasnt actually updated... I can't put a null in the column. What do I have to do to update the edmx properly? Thank you.

+2  A: 

Choosing the Update Model from Database is the best method for updating your EDMX. There are certain properties that don't get updated on the Conceptual layer.

Ensure that your Store layer has been updated by viewing it in the Model Viewer toolbox. If the Store has properly been updated then you're okay, and your database is in sync. If so, go into the visual designer, click the field, go to properties, and update the NotNull property on the Conceptual side.

bendewey
A: 

In my case the issue comes if I add a new table to my Database, when I click on Update Model From Database the new table doesn't appear, do I have to type it manually in the XML file? (pain in the neck).

Thanks Braulio

Braulio
+2  A: 

Update/delete from the EDMX is not always functional. If the model doesn't get updated on clicking Update Model from Database let's say when you have updated a view/table in the DB, do the following:

1) Delete the view/table from the model diagram
2) Switch the EDMX to xml view
3) Search and delete the xml entity elements
4) Switch back to EDMX view
5) Click Update Model from Database

This should reflect any kind of change you made to the DB to your EDMX. It's cumbersome, but works flawlessly.

In an ideal world, i would expect the Update Model from Database to sync the changes from DB to EDMX. But, it doesn't work most of the time.

pencilslate
Huagati has a tool to refresh the edmx file, but it's not free. http://www.huagati.com/dbmltools/
Junior Mayhé
+1  A: 

Yes, It doesn't work most of the time :-/

The "best method" (because it works systematically) is to delete the EDMX file and generate it again. But don't forget to remove the connection string in App.config (else VS2008 wizzard will add a suffix to the default entity name), and clear the cache.

I hope that these tools will work better in a next release, because it decreases the productivity dramatically...

littlesteps
Sadly, In VS 2010 RC2 it still works the same. I agree - its contraproductive and error prone. Deleting EDMX file is the only 100% verified way to make it working.
mare
A: 

Open the edmx file in the VS's XML editor and check to see if there were errors genned when the update was attempted.

  <!--Errors Found During Generation:
      warning 6013: The table/view 'foo.dbo.snafu' does not have a primary key   
      defined and no valid primary key could be inferred. This table/view has  
      been excluded. To use the entity you will need to review your schema,  
      add the correct keys and uncomment it.

  <EntityType Name="snafu">
    <Property Name="snafu_column" Type="smallint" />
  </EntityType>-->

In the above case...Adding a primary key to the table in question caused the "Update Model from Database" to work.

w4ik
+1  A: 

It doesnt update for example max length for string attributes!

If you work with TFS it is not good to delete the file, you want to keep the history and not affect others.

For me it works having a tiniy separate project that I can use to completely recreate the edmx file, I open it in xml, copy paste to the existing one, and move one shape in the model in order for VS to recreate the .cs file. Voila, it is now updated.

mape1082
There are third party tools that can keep it in sync, including maxlength, precision/scale, default values, identity/computed etc. One tool is my add-in for VS2010. If you want to see it in action, watch the screencast videos in these two blog posts: http://bit.ly/cTbreP http://bit.ly/cCbnrn You can download the addin and get a trial license at http://huagati.com/dbmltools/ if you want to try it out...
KristoferA - Huagati.com