简体   繁体   English

如何重新生成EDMX文件?

[英]How to regenerate EDMX file?

I'm working on a .Net 4.0 project which uses Entity Framework 4. Our underlying data model has changed and I'd like to update the Entity Framework components, specifically the model's EDMX file. 我正在开发一个使用Entity Framework 4的.Net 4.0项目。我们的底层数据模型已经改变,我想更新Entity Framework组件,特别是模型的EDMX文件。 Currently I'm doing this task manually and it's both time consuming and error prone. 目前我手动执行此任务,既耗时又容易出错。

Is there a way to regenerate the EDMX file automatically? 有没有办法自动重新生成EDMX文件?

In addition, I would prefer if the model classes are NOT regenerated, as these have been extended with additional logic. 另外,我更希望是否重新生成模型类,因为这些类已经使用其他逻辑进行了扩展。 I'm okay with manually editing these classes, I just want an automated way to generate the EDMX file. 我可以手动编辑这些类,我只想要一种自动生成EDMX文件的方法。

In the Model Browser or the Model Diagram you can right-click and use the Update Model from Database... functionality. 在模型浏览器或模型图中,您可以右键单击并使用“从数据库更新模型...”功能。 However, this will regenerate the classes, as it should. 但是,这将重新生成类,因为它应该。

I think you should reconsider editing the model classes directly and instead use partial classes to extend their functionality (the generated classes are partial by default). 我认为你应该重新考虑直接编辑模型类,而是使用部分类来扩展它们的功能(生成的类默认是部分的)。

You can also edit the model template files (.tt file when you expand the .edmx file) to generate them in the way you want. 您还可以编辑模型模板文件(展开.edmx文件时的.tt文件)以按您希望的方式生成它们。 Search for T4 templates to find tutorials regarding this. 搜索T4模板以查找有关此内容的教程。

There is no automatically refresh the EDMX (it will be nice from MS if they implement that at some point) and the best and most accurate way to refresh the EDMX is by deleting all tables in the Diagram and then deleting all complex types etc. in the Model Browser. 没有自动刷新EDMX(如果他们在某些时候实现这一点,它会很好用)并且刷新EDMX的最佳和最准确的方法是删除图中的所有表,然后删除所有复杂类型等。模型浏览器。 After that regenerate the EDMX by right click on the Diagram then click on Update Model from Database... 然后右键单击Diagram重新生成EDMX,然后单击Update Database from Database ...

I will not suggest expanding on .tt files though as they will be gone the next time you regenerate the EDMX classes, rather have a model project or a DTO project where you can handle reflecting the EDMX properties and do your manipulation for your data there. 我不会建议扩展.tt文件,因为它们将在下次重新生成EDMX类时消失,而是有一个模型项目或DTO项目,您可以在其中处理反映EDMX属性并对您的数据进行操作。

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

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