3

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

Rasto
  • 17,204
  • 47
  • 154
  • 245
  • 1
    I won't be able to answer all those questions, so I just put my comments here. EF4.1 simplified Model also based on T4 templates, so the difference is DBContext based API in EF4.1 only expose most used methods compared to ObjectContext in EF4.0. Yes, your can have POCO classes in another project. – J.W. Mar 23 '11 at 19:29
  • @J.W. please feel free to answer any subset of those questions that you are able to answer. Maybe the complete answer will require multiple partial answers from different wonderful people who wants to help me. – Rasto Mar 23 '11 at 19:33

1 Answers1

4

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.
Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • +1 thank you great answer. I'm more and more decided to use new API. One more think - I has read that unique indexes are not supported in EF 4. Wander if they are still unsupported in EF 4.1 ? – Rasto Mar 24 '11 at 06:51
  • 1
    @drasto: No Unique keys are not supported in EF 4.1. EF 4.1 builds on the same core so there are no additional feature. Unique keys are expected feature in the next major version: http://www.ladislavmrnka.com/2011/03/unique-key-constraints-in-entity-framework/ – Ladislav Mrnka Mar 24 '11 at 07:55
  • I've read the block that you link on your site. It looks really promising. Wander if you have any information on when the beta can be released ? – Rasto Mar 24 '11 at 09:12
  • No I don't have any information. I expect it as part of the next .NET version. – Ladislav Mrnka Mar 24 '11 at 09:14