entity framework – What are each of the template types intended usage, pros and cons? – Education Career Blog

I have not hardly touched EF4, but I’ve used Linq to sql quite a lot. I would like to start into one of the EF templates but I have no idea what situations make sense for each or what their intent was.

I have the following possibilities:

  • Data templates
    • ADO.NET Entity Data Model
    • Service-based Database (is this even related to EF?
  • Code templates (I am familiar with T4)
    • ADO.NET EntityObject Generator
    • ADO.NET Self-Tracking Entity Generator
  • Online Templates
    • ADO.NET C# POCO Entity Generator

,

I have no idea what situations make
sense for each or what their intent
was

Not meaning to sound rude, but did you have a look on MSDN/ASP.NET to find out? There is plenty of information around. And there is a lot to each of those templates, more than i can go into here. There is a MSDN page for each of these.

That being said, i’ll give you a quick summary, so people who stumble here have some info.

ADO.NET Entity Data Model

This is the file you create to use Entity Framework as your ORM, and it is mandatory for using EF. You need this before you use any of the others. You can create your EDM with a number of different approaches, including database-first (generate from DB), code-first, model-first, etc.

Service-based Database

I have never heard of this term, and given i’ve been working with EF a lot lately (and reading), i doubt this will be related to EF.

ADO.NET EntityObject Generator

Generates classes for entities which inherit from the EntityObject class. Identical to the default EF code generator, except instead of putting output code into the Model.edmx.designer.cs (default) file, the code gets put into seperate files. I personally don’t see any benefit in this template.

ADO.NET Self-Tracking Entity Generator

Generates classes for entities when you want to develop N-Tier applications (ie if you wanted to allow a WCF/Silverlight app to work with your model). Entities are setup to be ‘trackable’ by the EF Graph, in order to handle persistence operations from various applications.

ADO.NET C# POCO Entity Generator

My favourite. 🙂 Generates classes for entities which inherit from nothing. They have no idea that they are being used for persistence. Use this for applications when you want persistence-ignorance, testability and loose-coupling of your domain/persistence layers.

Leave a Comment