Entity Framework 4.1 RC: Including Code-First


Microsoft has published the first release candidate of Entity Framework 4.1.  This new release includes the very popular Code First feature, allowing to model your data in the code, without any designer tools.

With this Release Candidate comes a promise:  the final release will come within the next 4 weeks and will be %100 compatible with the current RC.

If you’ve read my blog post about EF POCO capability, you’ve seen that Entity Framework currently lacks support for a clean class model, i.e. a set of classes representing your data but totally freed of dependencies to the Entity Framework (via base classes, attributes, etc.).

With Entity Framework 4.1, this changes.  We can now model classes in a POCO fashion and the Entity Framework will map to them.

You can find a simple walkthrough at this blog post, so I won’t repeat it here.

I’ve just started to toy around with the RC.  So far I find it pretty neat.  The fluent API has a very natural feel for configuring different mapping.

The lack of documentation is quite painful at this point.  But hey!  If you’re an early adopter, you’re used to navigate blog posts talking about outdated versions of the CTP and using a lot of reflection!

A big feature of this RC is the ability to generate the database out of the model.  I found it pretty limited since EF 4.1 doesn’t include any support for ‘migration’, i.e. the capacity of adapting the database following a change in the class model.  Microsoft is working on it though and this should be available in a future release.  I’m not a huge fan of generating a database out of a class model (simply because it’s impractical in any Enterprise).  In order to make it work properly, you would need to decorate your model with attributes from System.ComponentModel.DataAnnotations namespace, otherwise the conventions will null all non-PK/FK columns and assume ‘standard’ string-size (128).  This doesn’t bring a dependency to EF directly, but it does charge your model with distraction, although the added ‘richness’ can then be used for validation.

My next step is to look into mapping inheritance into the data model.

Advertisements

2 thoughts on “Entity Framework 4.1 RC: Including Code-First

  1. Pingback: Entity Framework 4.1: Basics (1) « Vincent-Philippe Lauzon's blog

  2. Pingback: Entity Framework 4.1 Release to Web (RTW) « Vincent-Philippe Lauzon's blog

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s