问题
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
回答1:
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:
- 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.
来源:https://stackoverflow.com/questions/5410381/generate-poco-classes-from-model-using-t4-templates-vs-ef4-1-simplified-api-mod