Entity Framework CTP 2 : POCO

Just a quick start:


ie. I coded up this:

public class dbFSContext : ObjectContext
    public ObjectSet<Poll> Polls{get;set;}
    public dbFSContext()
      : base("name=dbFSEntities", "dbFSEntities")
            Polls = CreateObjectSet<Poll>();


  public class Poll
    public virtual int PollID { get; set; }
    public virtual string PollTitle { get; set; }

Then a little console app:
using (dbFSContext db = new dbFSContext())

        var polls = from p in db.Polls
                    select p;
        foreach (var poll in polls)


From above link:

Do I need an Entity Data Model before I can use POCO?

Yes – POCO support in Entity Framework 4.0 simply removes the need of having persistence specific concerns in your entity classes. There is still the need for you to have a CSDL/SSDL/MSL (collectively EDMX) metadata so that the Entity Framework is able to use your entities along with the metadata in order to enable data access. There is a separate effort that we are working on that will allow you to do true “code-first” development without the need to have a predefined EDMX model. A community preview of this feature will be released to the web in the coming months. We will roll this into the product the first chance we get. As always, your feedback will be helpful.

Do I have to always hand-craft these entities and the context?

No – there is a very powerful and flexible code generation mechanism in Entity Framework 4.0 that is based on T4 as Alex blogged about here. You can provide your own templates that allow you to build your entities in a way that you see fit. We are also working on providing standard out of the box templates that will generate POCO entities for you.

More info here:

Feature CTP Walkthrough: POCO Templates for Entity Framework
Feature CTP Walkthrough: Self Tracking Entities for Entity Framework

Does EF v4 going to support hi/lo key generation like NHibernate ?  Let me know if you have any information on it.  I’m not having much luck seeing all of what v4 will have outside of high level stuff


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s