NHibernate vs. Entity Framework: Usage
This is in a response to a question on twitter:
In general, for applications, I would always use NHibernate. Mostly because I am able to do so much more with it.
For one off utilities and such, where I just need to get the data and I don’t really care how, I would generally just use the EF wizard to generate a model and do something with it. Mostly, it is so I can get the code gen stuff ASAP and have the data working.
For example, the routine to import the data from the Subtext database to the RacconBlog database is using Entity Framework. Mostly because it is easier and it is a one time thing.
I guess that if I was running any of the tools for generating NHibernate model from the database, I would be using it, but honestly, it just doesn’t really matter at that point. I just don’t care for those sort of tools.
Comments
Unrelated to this post... your "Archive" (right hand bar) seems to be sorting by month number as text, hence Oct/Nov/Dec come between Jan and Feb
Marc, Yes, I know, we are doing some work on RacconBlog now, will be fixed soon
Thanks for this answer.
"Mostly because I am able to do so much more with it." Do you think about your NHibernate knowledge vs your EF knowledge or do you think about some NHibernate features not supported by EF? If you think about features what are the top ones you think about?
Mathieu, Because EF is really limited in many of its capabilities.
Indeed NHibernate has more features and extension points, however sometimes you need to dive into the source code to find out the meaning of an interface method.
I use EF when I'm in the mood to poke out my right eye.
I use NHibernate when I'm in the mood to poke out my left eye.
I wrote a detailed review of EF 4.1 CodeFirst RC vs NHibernate when this version came out. http://joseoncode.com/2011/03/30/entityframework-4-1-rc-code-first-review/
Basically, I won't use EF because is very limited, and for simple things I won't use NHibernate either just ado.net (maybe dapper because it has some nice extension methods).
With nuget there is no execuse for not using NHibernate either. Add package => nhibernate => done
My main production app was written with EF code-first. At first I loved it, but the more I use it the more "gotchas" I find. I don't really want to go through the whole thing and waste time replacing it with NHibernate (mostly since I used EF because there was better docs for learning EF4 than NH) but I definitely would use NH over EF for any new projects.
Most people who I found prefer EF of NH basically do so because Linq support is 'better'.
@jose thanks for the review I tried the new EF CodeFirst and after all it is'nt that bad if you want to quickly achieve some simple basic things. For complex projects there is no other solution then NH at the moment and i don't know if the better LINQ support in EF is a real argument against NH since there are a lot of other ways for querying data. Documentation is always an issue and the reference at nhforge is not complete and needs a rework. For instance there is no word about the new ConfORM feature and how to use it. The other issue is support. Jose wrotes: "The experts of nhibernate will answer your question in minutes." In the last couple of months it is really hard to get an answer. I asked some questions with unit tests etc. but without any success. Fabio answered a lot of questions in the past, but since he moved back from the project it is really quite in the forum. But in the end there is alyways ligth and shade :-)
Oren,
Did you marry someone from Microsoft? :-)
I just finished a couple of Windows Phone projectsI & I missed NHibernate a lot since had to use Linq to Sql the only choice for Sql CE for WP7.
I kind of agree with Jose; EF is very limited. I will not use that thing for anything serious at all.
EF is just good enough.
Here's my comparison, which I did when I started with EF 4.1: http://stackoverflow.com/questions/5101974/net-orm-comparison/5105917#5105917
Now I would add that convention-based mappers for NHibernate (ConfORM, Fluent) are much more mature and flexible.
EF's ONLY selling point is a more complete LINQ provider. Which, BTW, is not so great when you look at some of the horrible SQL it generates. Not to mention you can't pass entities to it (you need to pass the Id).
@Diego
You actually missed Entity Frameworks biggest selling point:
Its was made and is publicly endorsed by Microsoft.
Comment preview