简体   繁体   English

如何快速刷新ADO.NET实体数据模型?

[英]How to quickly refresh ADO.NET Entity Data Model?

I am using ADO.NET Entity Data Model in my C# project. 我在我的C#项目中使用ADO.NET实体数据模型。 There is an ADO.NET Entity Data Model that is generated on the DB in my project. 在我的项目中的DB上生成了一个ADO.NET实体数据模型。 How do I quickly refresh the ADO.NET Entity Data Model based on DB changes? 如何根据数据库更改快速刷新ADO.NET实体数据模型? I have been deleting the model and then creating a new one. 我一直在删除模型,然后创建一个新模型。 I believe that there is a more simple and quick way. 我相信有一种更简单快捷的方式。

Right-click on the model designer and choose "Update Model from Database", and a dialog box will pop up. 右键单击模型设计器并选择“从数据库更新模型”,将弹出一个对话框。 Click OK and your model will be refreshed. 单击“确定”,您的模型将刷新。

FYI, I'm using EF 4.0, and I skipped the earlier version, so I can't tell you what it's like in VS 2008. 仅供参考,我使用的是EF 4.0,我跳过了早期版本,所以我无法告诉你VS 2008中的情况。

Update Model from Database doesn't work very well. 从数据库更新模型不能很好地工作。 At least in VS 2008/C# 3.5. 至少在VS 2008 / C#3.5中。 I fails to remove old columns, etc. 我无法删除旧列等

I always Ctrl-A (to select everything), the press delete, and then create model from database from scratch - update just doesn't work right in a lot of cases. 我总是按Ctrl-A(选择所有内容),按删除,然后从头开始从数据库创建模型 - 更新只是在很多情况下不能正常工作。 At least in EF4 / VS2010 that I am developing in/with. 至少在我正在开发的EF4 / VS2010中。

右键单击 - 从数据库更新模型。

You should open your Model.edmx after that right click on the properties. 在右键单击属性后,您应该打开Model.edmx。 now select the (Update Model from Database) and it will going to show you another panel with tab panel. 现在选择(从数据库更新模型),它将显示另一个带选项卡面板的面板。 you can choose Add,Refresh and delete. 您可以选择添加,刷新和删除。 in your current situation, you should select Refresh. 在当前情况下,您应该选择“刷新”。 then select Tables->dbo->and name of your table in database and then click finish. 然后在数据库中选择Tables-> dbo->和表名,然后单击“完成”。 that's it. 而已。 you've refresh your table. 你刷新了你的桌子。

but sometimes you can see in your model that something went wrong because the column is not in right position. 但有时您可以在模型中看到出现问题,因为列不在正确的位置。 to solve that just right click the column name and select 'UP' to move it up or 'DOWN' to bring it down. 要解决这个问题,只需右键单击列名称,然后选择“向上”将其向上移动,或选择“向下”将其向下移动。

i hope that it will help. 我希望它会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM