There are all sorts of blog posts flying about at the moment regarding EF4’s Code First CTP: –
Since they all cover the finer details in excruiating detail, I wanted to just talk about my brief experience with it yesterday and today.
Firstly, installation is easy – just download the CTP, it installs a folder in Program Files that you reference in your .NET projects (Microsoft.Data.Entity.CTP).
Actually using it is extremely easy and quick, as the above blogs attest to – you can just create POCOs, put the type within your context and off you go – it really is that easy. Unfortunately I could find no way of actually viewing the database tables that the framework creates, as I’m using SQL Compact 4 (Code First does not (yet?) work with Sql Compact 3.5).
Anyway – just an example of how easy it was to create a simple two-tier inheritance hierarchy…
Here’s the code for it:
Not a lot of code really – and that’s about all that’s required in terms of set-up of code. Here’s an example of my using it – pretty standard Entity Framework really aside from the second line that tells EF to automatically update the database schema if you make changes to the object model: –
A just to prove that EF understands the inheritance hierarchy, here’s a screenshot with the output from the code above:
The nice thing about this is the ease of creation – you can be up and running with a database in literally minutes. Just hitting F5 with the code above will implicitly create a new database and the schema to match the object model. Nice.
I’m not sure how easily you could push updates post-deployment e.g. you’ve got a production database and want to amend some fields etc. – I believe that this sort of thing is still to come – but it’s still quite impressive.