简体   繁体   English

.NET 4.0 EDMX从模型生成数据库,然后执行SQL从表中删除数据

[英].NET 4.0 EDMX Generate DB from model and then Execute SQL removes the DATA from Table

I'm newbie with .NET Entity Framework 4.0 I'm using VS2010 and I created the EDMX file and then added my Entities in this model. 我是.NET Entity Framework 4.0的新手,正在使用VS2010,创建了EDMX文件,然后在此模型中添加了实体。 After I've finished my Datamodel and set the Asscociation, I right click on and choose Generate DB from model. 完成数据模型并设置Asscociation后,右键单击并选择“从模型生成数据库”。

Then it creates SQL scripts *.sql then I open the SQL and right click on Execute SQL Statements... What happens is all my tables are re-created... 然后创建SQL脚本* .sql,然后打开SQL并右键单击Execute SQL Statements ...发生了什么事,所有表都重新创建了...

ISSUE: All my test data in MasterData Tables are removed/deleted. 问题:我在MasterData表中的所有测试数据都已删除/删除。 I need to add the data back again manually... 我需要手动重新添加数据...

I googled on "keep data generated Data model EDMX" etc. but couldn't find... Can someone advice me how I can avoid this problem? 我在“保持数据生成的数据模型EDMX”上进行了搜索,但是找不到...有人可以建议我如何避免此问题?

Because I've e..g 15 MasterDataTable + other tables linked with these and I need to re-add the records back manually for all these tables... and 9 of 10 case I don't touch those tables in UI. 因为我有例如15个MasterDataTable和其他与之链接的表,所以我需要为所有这些表手动重新添加记录...以及10种情况中的9种,我不会在UI中碰到那些表。

please advice how I can avoid this situation. 请建议我如何避免这种情况。

thanks 谢谢

You can update the model from the database (the reverse way you are taking now): 您可以从数据库中更新模型(采用与现在相反的方式):

Double click the .edmx file to open the designer. 双击.edmx文件以打开设计器。 In the middle of the designer, right click to show the contextual menu and click "update model from database". 在设计器的中间,右键单击以显示上下文菜单,然后单击“从数据库更新模型”。 It will prompt a screen, check the DB parameters and click next. 它将提示一个屏幕,检查数据库参数,然后单击下一步。 Now, you're in a sreen with TABS. 现在,您对TABS感到恐惧。 The first tab is for adding tables as entities to the model. 第一个选项卡用于将表作为实体添加到模型。 The second tab will its for update the model. 第二个选项卡将用于更新模型。 Select the tables and views you need to add/update and click next. 选择您需要添加/更新的表和视图,然后单击下一步。 That's all. 就这样。

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

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