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

Viewed 95402
  • 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.

11 Answers

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.

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

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.

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.

Related