实体框架 4.1 设计器可以“从数据库更新模型”吗?仅适用于选定的实体?

发布于 2024-11-14 23:06:24 字数 350 浏览 5 评论 0原文

情况:有时,数据库模式并不是您所认为的系统信息的理想表示,并且您可能无法更改它。我们一直在使用实体框架创建一个更好的概念模型,以便在这种情况下进行编码。这意味着从数据库更新模型,然后通过设计器或直接使用文本编辑器直接通过 .edmx 文件自行更改模型。

问题:当您从数据库更新模型时,您精心做出的所有更改都将被抛到九霄云外。这可能会使添加新实体变得非常麻烦,因为您基本上被迫通过直接编辑 .edmx 文件来完成此操作。

问题:有没有办法让实体框架只更新数据库中选定的实体?或者是否可以告诉它在添加新实体时保留模型的其余部分?

谢谢!

The situation: Sometimes a database schema is not what you would consider an ideal representation of the system's information and you may not be able to change it. We have been using Entity Framework to create a nicer conceptual model to code against in situations like this. This means updating the model from the database and then changing it ourselves, either through the designer or through the .edmx file directly using a text editor.

The problem: When you update the model from the database, all your carefully made changes are thrown out the window. This can make adding new entities a real hassle as you are basically forced to do it through editing the .edmx file directly.

The question: Is there a way to get the Entity Framework to only update selected entities from from the database? Or is it possible to tell it to leave the rest of the model alone when adding a new entity?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷鸟归林 2024-11-21 23:06:24

不,无法使用内置设计器进行选择性更新。此外,设计师不会丢弃您的所有更改。它通常不会触及概念模型(除了在极少数情况下不断重命名某些关联)和映射,但它总是删除存储模型并用新定义覆盖它。我在修改概念模型以及映射和运行数据库更新方面没有任何问题。

设计器与 Visual Studio 中的任何其他设计器一样工作 - 不支持触​​摸生成的代码(存储模型)功能。一旦你这样做了,你就不能再使用从数据库更新了。

有一个商业工具可能支持更好的模型更新 - 你可以尝试一下。

No there is no way to make selective updates with built-in designer. Also the designer doesn't throw away all your changes. It usually doesn't touch conceptual model (except some rare occasions where it continuously renames some associations) and mapping but it always deletes storage model and override it with new definition. I worked without any problem with modifications to my conceptual model and mapping and running updates from the database.

Designer works as any other in Visual Studio - touching the generated code (storage model) is not supported feature. Once you do it you cannot use Update from database anymore.

There is commercial tool which probably supports better model updating - you can try a trial.

沒落の蓅哖 2024-11-21 23:06:24

如果通过更新选定的实体,您的意思只是一个或多个表,您可以从模型中删除这些表,然后将它们单独添加回来,以通过单独选择它们来拉入更改表 - 我经常在基础表发生更改时这样做(特别是在开发过程中)。

在将实体/表拉入模型后,您最终会丢失对这些重新添加的实体所做的任何手动更改(即,我经常重命名我的导航属性,然后在每次重新导入表后,我需要手动重命名它们再次)。

If by updating selected entities, you mean just one or more tables, you can delete those tables from the model, and then add them back in individually to pull in changes tables by choosing them individually - I do that often as underlying tables are changed (especially during development).

You do end up losing any manual changes you made to those re-added entities after the entity/table was pulled into the model (i.e. I often rename my navigation properties and then after each re-import of the table I need to manually rename them again).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文