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

前端 未结 11 2100
遥遥无期
遥遥无期 2020-12-04 11:59
  • 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, rig
相关标签:
11条回答
  • 2020-12-04 12:45

    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.

    0 讨论(0)
  • 2020-12-04 12:59

    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.

    0 讨论(0)
  • 2020-12-04 13:00

    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:

    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.
    0 讨论(0)
  • 2020-12-04 13:00

    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!

    0 讨论(0)
  • 2020-12-04 13:01

    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.

    0 讨论(0)
  • 2020-12-04 13:02

    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.
    0 讨论(0)
提交回复
热议问题