I use NHibernate since its first versions and I really love it :), but after Entity Framework 4.1 is out, I started to consider using EF for people that actually does know anything of ORM and still work with dataset or use handwritten SQL CRUD, but could not use open source project or prefer using MS technologies.
I tend not to agree with this path, but sometimes it is easier to tell people, â€œhey, just install this update of Microsoft and you can use EF code first, or if you want a designer you can simple add a new EF Model to the projectâ€. People tend to consider less work using something that is already included in the framework, instead of going toward some external open source library. I must also admit that using EF 4.1 is quite fun (I used in really little projects, but 4.1 version gave me a good impression).
If you want to use EF4.1 in your application you need to do very little steps, suppose you have this class to persist.
You need to reference the Ef4.1 assembly and then create a Context to be able to persist this class.
Now go to app.config (or web.config) and create the connectionstring to the database with the same name of the context class (thus it is named BattlefieldContext)
Now write the code that insert a Warrior into the database.
Run these few lines of code, everything works, but waitâ€¦. you never created the database but no exception occurs. This happens because the current user has administrative rights on the Sql Server, so, after the connection to the database engine was opened, EF41 verified that the Battlefield database did not exists, so he created one to persist the Warrior class.
Generation of the database is straightforward, EF41 generates a table with a column for each property of the object that needs to be persisted, and he got special care for property named Id, because it is the primary key in the table. Since the Id property is an integer, the default convention creates a primary key with Identity Specification turned on. If you read all rows in the table you can verify that the warrior Raistlin was really saved into database.
You should admit that using EF41 in such a simple scenario is damn simple and efficient, very few lines of code and you are ready to use it.