使用 T4 模板与 EF4.1 简化 API 模型优先方法从模型生成 POCO 类
我有与视觉设计师一起创建的模型。现在我想要从中生成 POCO 类。在我的另一个问题中,有人向我建议了 EF4.1 简化 API 模型优先方法。之前我也在考虑T4模板。
与使用 T4 模板生成 POCO 类相比,EF4.1 简化 API Model First 有哪些限制? EF4.1 方法有什么优点(如果有的话)(除了它应该更易于使用)?我现在的决定将很难撤销,因为我将有相当大的持久层,所以将来可能很难对其进行更改。
特别是,我对这个功能很感兴趣:
- 每次更改模型(在可视化设计器中)时,我是否可以获取这两个选项中的任何一个来生成数据库表,这样我就不必生成查询并运行它们?这将大大加快我的开发过程(由于某种原因,我每次更改模型时都必须手动删除表,因此需要花费大量时间)。我知道这可以通过
- 我可以在另一个项目中拥有 POCO 课程来完成吗?我知道这可以是带有 T4 模板的圆顶,但是使用简化的 API 也可以吗?
- 生成的 POCO 类中的属性是否可以进行注释,而不会在每次从模型重新生成时被覆盖? (这确实可以通过代码优先的方法实现)
- 效率上有什么区别吗?
如果重要的话,所选择的任何技术都将在 ASP.NET MVC 应用程序中使用。
编辑: 如果您知道答案,请回答我的问题的任何子问题。也许与另一个部分答案一起它会给我我需要的信息。谢谢
I have model created with visual designer. Now I want to have POCO classes generated from it. In another question of mine, EF4.1 simplified API Model First approach was suggested to me. Before I was also thinking about T4 templates.
What are the limitation of EF4.1 simplified API Model First comparing to using T4 templates to generate POCO classes ? What are advantages to of EF4.1 approach if any (besides it is supposed to be simpler to use)? My decision now will be very hard to undone as I will have quite huge persistence layer, so it might be hard to make changes to it in future.
Particularly, I'm interested in this features:
- can I get either of those 2 options to generate database tables every time I change model (in visual designer) so I don't have to generate queries and run them ? That would speed up my development process a lot (for some reason I have to drop tables manually every time I change model so it takes a lot of time). I know this can be done with
- can I have POCO classes in another project ? I know this can be dome with T4 templates but is it also possible with simplified API?
- can properties in generated POCO classes be annotated without being overwritten every time they gets regenerated from model ? (this is indeed possible with code-first approach)
- is there any difference in efficiency?
If it matters any technology chosen will be used in ASP.NET MVC application.
EDIT:
Please answer any subquestion of my question if you know the answer. Maybe together with another partial answer it will give me the information I need. Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EF 4.1 提供了简化的 API,这主要是因为 EF 中首次提供了代码优先方法。您所描述的是模型优先方法。
我已经回答了类似的问题,但我会尝试回答您的个人问题:
EF 4.1 provides simplified API mostly glorified because of the code first approach available in EF for the first time. What you describe is the model first approach.
I already answered similar question but I will try to answer your individual questions: