将表重新添加到实体模型(edmx)时不显示
我有一个有 5 个表的数据库。一开始,我添加了这些表,但后来由于某些关系编译错误而决定删除一些表。
现在,当我想将它们添加回来时,我打开 edmx 文件 ->从数据库更新模型...我在添加选项卡下看不到这些表,而只在“刷新”选项卡下看到这些表。
我怎样才能将它们添加回来?
I have a db with 5 tables. At the beginning, I've added those tables in, but then decided to remove some due to some relationship compile error.
Now, when i want to add them back, i'm opening the edmx file -> update model from database... I don't see those tables under add tab, but only under the "refresh" tab.
How can i add them back?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
为了将表重新添加到模型中,您首先需要从模型中删除该表。 (表列表在 [model.Store] 树中可见(请参阅“模型浏览器”窗格 - 您可以通过鼠标右键单击菜单将其打开)。
当您运行“从数据库更新模型...”时,该表将出现在“更新向导”第一步的“添加”选项卡中。
完成步骤:
工作室。
文本编辑器。
xml 实体元素(参见注释
以下)。
工作室。
数据库。
要删除模型中表的所有引用:
删除所有“EntitySet”子元素
'Name' 属性设置为
值 [TableNameToReAdd]。
'EntityContainer' 元素,全部删除
'AssociationSet' 子元素,其中
存在一个“End”元素
他们的 'EntitySet' 属性设置为
值 [TableNameToReAdd]。
'EntityContainer' 元素,全部删除
'EntityType' 子元素,其中
'Name' 属性设置为
值 [TableNameToReAdd]。
'EntityContainer' 元素,全部删除
'Association' 子元素
存在“End”元素,它们有自己的
“角色”属性设置为值
[要重新添加的表名称]。
In order to re-add a table to your model you will first need to delete the table from your model. (a list of tables is visible in the [model.Store] tree (see 'Model Browser' pane- you can open it from right-mouse click menu).
When you run 'Update model from database...' the table will appear in the 'Add' tab in the first step of the 'Update Wizard'.
Steps to complete:
Studio.
text editor.
the xml entity elements (see notes
below).
Studio.
Database.
To delete all references to a table in your Model:
delete all 'EntitySet' child elements
that have the 'Name' attribute set to
the value [TableNameToReAdd].
'EntityContainer' element, delete all
'AssociationSet' child elements where
an 'End' element exists that have
their 'EntitySet' attribute set to
the value [TableNameToReAdd].
'EntityContainer' element, delete all
'EntityType' child elements where
that have the 'Name' attribute set to
the value [TableNameToReAdd].
'EntityContainer' element, delete all
'Association' child elements where an
'End' element exists that have their
'Role' attribute set to the value
[TableNameToReAdd].
我阅读了这个和其他搜索选项,但最后我找到了另一个答案,可以帮助我解决这个问题。
解决了我的问题的链接问题。
已更新
如果有时您完成了一切正常,但仍然没有反映添加新列或更改数据类型的更改。
最好的方法是尝试手动更新,仍然没有希望,然后按照 @mathijsuitmegen 的建议,删除并添加表,但这是最后一个首选选项。
I reading this and other searching option, but finally I have found another answered which help me to short-out this issue.
Link which solved my issue.
Updated
If some time you done everything fine, still does not reflect the changes either adding a new column or change data-type.
The best way of this try to update manually, still there is no hope, then as suggested @mathijsuitmegen, delete and add the table, but this is last option to prefer.
一个更简单的解决方案是在
下的
模型浏览器
中删除未显示的表格。然后右键单击模型“
从数据库更新
”,表格应该就在那里。An easier solution is in the
Model Browser
underdelete the table not showing up. Then right click on the model "
update from database
" and the table should be there.您想要在模型中删除实体后重新添加该实体。
除了编辑 edmx 文件之外,还有另一种方法可以做到这一点。
您必须从数据库中临时删除该表。
注意:如果数据库尚未投入生产,我只会这样做!
因此,首先在 SQL Server Management Studio 中创建一个脚本:
右键单击与模型中缺少的实体对应的表。选择“将表脚本为”、“创建到”、“新查询编辑器窗口”。
第二步是删除表。再次右键单击并选择“删除”。确认删除。
返回 Visual Studio 更新模型。
返回 SQL Server Management Studio 并运行您刚刚创建的“创建”脚本。
该表将再次添加到您的数据库中。
在 Visual Studio 中,您现在可以再次更新,您的表格将显示在“添加”选项卡下!
You want to re-add an entity after it is deleted in the model.
Besides editing the edmx file there's another way to do this.
You will have to temporary delete the table from the database.
note: I would only to this if the database is not in production yet!
So in SQL Server Management Studio first create a script:
right click on the table(s) that correspond with the missing entity in your model. Select 'Script Table as', 'CREATE To', 'New Query Editor Window'.
The Second step is to delete the table. Right click again and select 'Delete'. Confirm the delete.
Back in Visual Studio do an update of the model.
Go back to SQL Server Management Studio and run the 'create' script you have just created.
The table will be added to your database again.
In Visual Studio you can now do an update again, your table will show up under the 'add ' tab!!!
除了上面需要从模型中删除的引用列表之外,如果您的表与其他表具有关联关系,还请考虑删除 AssociationSetMapping 元素。
In addition to the above list of references that need to be deleted from the model please consider removing AssociationSetMapping element as well in case if your table has associative relationship with other tables.