Stuck In Baghdad
Stuck In Baghdad

Reputation: 629

Updating your edmx to reflect changes made in your db (.net linq-to-entities)

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.

Upvotes: 45

Views: 98975

Answers (11)

mape1082
mape1082

Reputation: 11

It doesn't 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 tiny 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.

Upvotes: 1

DeveloperDan
DeveloperDan

Reputation: 4684

A view I created in the database was not appearing in the designer (after choosing "Update model from database..." and adding a check next to the name of the view). I saw no error message until I switched the EDMX to xml view:

  • Right click the edmx file
  • Select "Open With..."
  • Select "Automatic Editor Selector (XML)"
  • Click Find and search for your view name

In the edmx xml I found:

"Errors Found During Generation: warning 6013: The table/view '(view name)' 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."

I modified the view to have a primary key. Then I opened the edmx designer and ran "Update model from database..." and the view then appeared in the designer as expected with no errors.

Upvotes: 1

alexey
alexey

Reputation: 801

Removing all tables from designer view and Updating after that works for me

Upvotes: 0

Peter Klein
Peter Klein

Reputation: 1010

What I have successfully done is this (VB.Net).

  1. make updates to the database as desired/ required
  2. Choose "Update from database" in the EDMX model, the graphical model will correctly show the new structure/tables
  3. Expand the project so that it shows all related files
  4. The two files with the "tt" extension are the ones that matter: first take the one WITHOUT the .Context. before the tt extension. right click on it and choose Run Custom Tool:

run custom tool

  1. Do the same for the .tt file with the .Context. in its name. All of your code and logical model classes will be updated.

Upvotes: 21

jagad89
jagad89

Reputation: 2643

1.Build the project after updating EDMX file.

2.Right click your .tt file in solution explorer.

3.Select "Run Custom Tool" option.

This will update the .tt file.

Source : here!

Upvotes: 4

BillDarcy
BillDarcy

Reputation: 340

This answer is better: https://stackoverflow.com/a/23886016/1014884

Any manual editing is ripe for errors or will be lost when someone uses any tool like the wizard. Deleting and updating with the wizard is much better.

Upvotes: 2

stackPusher
stackPusher

Reputation: 6512

THIS IS THE QUICKEST EASIEST WAY:

  1. Delete the view/table from the .edmx diagram.
  2. NOW use the Update Model from Database to add the table back in.

Upvotes: 4

pencilslate
pencilslate

Reputation: 13068

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 (right click the edmx file and select "Open With")
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.

Upvotes: 81

w4ik
w4ik

Reputation: 1276

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.

Upvotes: 2

littlesteps
littlesteps

Reputation: 51

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

Upvotes: 5

bendewey
bendewey

Reputation: 40235

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.

Upvotes: 14

Related Questions