使用T4模板从模型生成POCO类与EF4.1简化API模型第一种方法模型、种方法、模板、API

2023-09-03 04:07:32 作者:何以解憂?唯有暴富

我有一个可视化设计器创建的模型。现在,我想有从它生成的POCO类。在我的另一个问题,EF4.1简化API模型第一种方法是向我建议。之前我还想着T4模板。

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.

什么是EF4.1简化API模型首先要比较使用T4模板来生成POCO类的限制?有什么优势EF4.1办法(如果有的话,除了它应该是简单的使用)?现在我的决定将是非常困难的撤销,我将有相当庞大的持久层,所以它可能是很难使未来的修改。

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:

在我能得到其中的任意2个选项每次我改变模型(视觉设计师)生成数据库表,所以我没有产生疑问和运行呢?这将加快我的发展过程中有很多(出于某种原因,我不得不这样需要花费大量时间手动每次更改模式删除表)。我知道这可以用做 在我能有POCO类在另一个项目?我知道这可能是圆顶T4模板,但它也可以用简单的API? 可以生成POCO类的属性,而不每次会从模型再生时间被改写注解? (这确实是可能的code-第一种方法) 有效率有什么区别?

如果它的事项选在ASP.NET MVC应用程序将使用的技术。

If it matters any technology chosen will be used in ASP.NET MVC application.

编辑: 请回答我的问题,任何subquestion如果你知道答案。也许连同另一部分答案,它会给我我需要的信息。谢谢

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

推荐答案

EF 4.1提供了简化的API主要是荣耀的,因为在code第一个可用的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.

我已经answered类似的问题,但我会尽量回答您的个性化问题:

I already answered similar question but I will try to answer your individual questions:

中的DbContext API 在主要的限制是缺乏信息。我们知道新的功能,但我们仍然不知道如何实现在ObjectContext的API提供的一些功能(简化可能去掉了一些功能)。我不知道这是如何涉及到模型第一approch用的DbContext发电机T4模板,因为在这种情况下,映射在EDMX仍然被定义文件,因此一些知名的问题与code首先映射应该加以克服。 在生成数据库的工作automtic用的DbContext API。默认情况下,ObjectContext的API只提供数据库脚本生成,你必须执行该脚本。在另一方面,如果你有VS 2010 premium版或旗舰版,您可以下载的实体设计数据库发电组,这将使你incrementaly建立数据库,而无需每次删除。这是什么不可能的的DbContext API的时刻。 您可以POCO类(模板)与两个API等项目。 是即使有T4模板生成的POCO类you可以使用标注。 在没有有效率无差异。的DbContext API只是包装器上的ObjectContext的API之上。 Main limitation of DbContext API is lack of information. We know new features but we still don't know how to achieve some features available in ObjectContext API (simplification probably removed some features). I'm not sure how this relate to the model first approch with DbContext generator T4 template because in this case mapping is still defined in EDMX file so some well known problems with the code first mapping should be overcome. Generating database works automtic with DbContext API. ObjectContext API by default offers only db script generation and you must execute the script. On the other hand if you have VS 2010 Premium or Ultimate you can download Entity designer database generation power pack which will allow you building your database incrementaly without deleting it every time. That is something not possible with DbContext API at the moment. You can have POCO classes (templates) in other project with both APIs. Yes even with T4 template generating POCO classes you can use annotations. No there is no difference in efficiency. DbContext API is just wrapper on top of ObjectContext API.