Top 5 Features of Code First Entity Framework CTP4

 

The latest release of Entity Framework CTP4 has some nice but unexpected changes. They introduced DbContext and DbSet to simplify model caching, database provisioning, schema creation and connection management. Here are my top 5 favorite features of the release.

  1. Less code and fewer Concepts. The coolest part is the use of convention over configuration. See the Productivity Improvements walk through and Conventions for code first. I like the extra touch that DbContext  will create the database for you if you want. No code to write. Just use the default CreateDatabaseOnlyIfNotExists.
  2. Simplified Database Experience. With the introduction of DbContext and DbSet. EF now takes care of database provisioning, schema creation and connection management. Nice! My favorite part is the Interface IDbConnectionFactory to allow creation of your own conventions.
  3. Backwards Compatible. Yes, this is a feature when it comes to CTP’s and Betas. Some projects might just throw stuff away or completely change things on you. EF allows you to still use ObjectContext or Data Annotations for advanced scenarios where common conventions don’t work for you.
  4. Simplified Configuration Experience. As I mentioned you can use annotations for this but you also have another cool option. DbContext includes a virtual method that can be overridden to do configuration right in the class. This means no need for separate configuration classes now. I definitely like having it all in one place. Much cleaner and easy to read.
  5. Testability IDbSet<TEntity> allows you to define an interface that can be implemented by your derived context. This allows the context to be replaced with an in-memory test double for testing.

Leave a Reply

Your email address will not be published. Required fields are marked *