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

前端 未结 11 2101
遥遥无期
遥遥无期 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 13:03

    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.

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

    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.

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

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

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

    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.

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

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

    0 讨论(0)
提交回复
热议问题