ADO.NET Entity Framework: Update Wizard will not add tables

后端 未结 13 1336
陌清茗
陌清茗 2020-12-13 11:55

I added a new ADO.Net Entity Data Model into my project and used the Update Wizard to add tables into the model. Five of the selected tables were added to the design surfac

相关标签:
13条回答
  • 2020-12-13 12:26

    Just throwing out some more detail for anybody who has not had to do this before. I am using visual studio 2013 with update 4 installed. I added some fields to a table, deleted the table from my model then went to update and it would not let me check any of the tables.

    I do have a primary key.

    I created a new test table, that showed up and it would let me check it but not my original.

    I have never opened it in XML before and did not know how to do that. You right click on the .edmx file and "open with" -- choose the xml editor.

    the table in question was there all right, it even had the new fields (strange).

    I deleted all the references to it (took a couple times) -- after you delete one and save, if you try to open it and it won't display just go ahead and choose "view XML" - look at the errors and basically follow the bouncing ball until you have cleaned it up.

    hope the extra detail helps somebody.

    Joe

    0 讨论(0)
  • 2020-12-13 12:29

    My solution to this is to delete the entire model and readd it including the new tables that I want.

    I accidentally deleted a table in the designer once and could not readd it. Hence removing entire model and readding it.

    I had some issues with this as well (Ado.Net Entity Data Model Not Updating Correctly)

    0 讨论(0)
  • 2020-12-13 12:33

    The design surface is different from the entity model. It is possible to have a table in the mapping in your EDMX which does not appear on the design surface. View the file as XML to see if this is the case. In this case, the Update Wizard will not allow you to re-add the tables, since they are already part of the entity model. So, generally speaking, the Update Wizard knows more about your entity model than it does about the design surface, per se.

    I don't think that's exactly the situation you're in, but it should give you the general idea for the solution: go into the XML and look for references to the tables in question.

    0 讨论(0)
  • 2020-12-13 12:34

    This has been resolved in latest version(environment: VS 2012 , .net framework 4.5). Simple open the .edmx file and add the required tables / stored procedures / views. The table/view which doesnt have primary key will be created as read only table/view.

    The table/view 'TABLE_NAME' does not have a primary key defined. The key has been inferred and the definition was created as a read-only table/view.

    0 讨论(0)
  • 2020-12-13 12:35

    Set Primary Keys to all tables or just one unchecked check-box "Allow null" to any column of each table. It works for me :)

    0 讨论(0)
  • 2020-12-13 12:36

    One easy way I found was to (in SQL Server Management Studio) add an ID column of type INT, deselect "Allow Nulls", and under Column properties (of ID) >> Identity Specification >> check (Is Identity), and make sure increment is set.

    Once the above is done, go back to your .edmx window, right-click, and Update Model from Database.

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